Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support windows #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "standard",
"extends": ["standard", "prettier"],
"overrides": [
{
"files": ["__tests__/**/*.js"],
Expand Down
193 changes: 193 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,30 @@
"devDependencies": {
"babel-preset-env": "^1.6.1",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.15.0",
"eslint-config-standard": "^14.1.1",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"husky": "^0.14.3",
"jest": "^26.0.0",
"lint-staged": "^7.1.0"
"lint-staged": "^7.1.0",
"prettier": "^2.2.1",
"pretty-quick": "^3.1.0"
},
"jest": {
"testURL": "http://localhost/"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.js": [
"eslint"
"eslint",
"prettier --write"
]
}
}
11 changes: 6 additions & 5 deletions src/getFileList.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
const fs = require('fs');
const glob = require('glob');
const argv = require('minimist')(process.argv.slice(2));
const fs = require("fs");
const glob = require("glob");
const argv = require("minimist")(process.argv.slice(2));
const posixSeparatedCwd = require("./posixSeparatedCwd");

const isDirSync = (pathName) =>
fs.existsSync(pathName) && fs.lstatSync(pathName).isDirectory();

const getFileList = (
inputFiles = [],
{ include = '**/*', cwd = process.cwd() } = {}
{ include = "**/*", cwd = posixSeparatedCwd() } = {}
) => {
if (inputFiles.length === 0) {
return glob.sync(include, {
cwd,
absolute: true
absolute: true,
});
}
if (inputFiles.length === 1 && isDirSync(inputFiles[0])) {
Expand Down
5 changes: 5 additions & 0 deletions src/posixSeparatedCwd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const path = require("path");

module.exports = function posixSeparatedCwd() {
return process.cwd().split(path.sep).join(path.posix.sep);
};
32 changes: 18 additions & 14 deletions src/rules.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,46 @@
const getExtendedRules = (root = '', rules) => {
const posixSeparatedCwd = require("./posixSeparatedCwd");

const getExtendedRules = (root = "", rules) => {
const extendedRules = rules;
rules.forEach((rule) => {
const splittedRule = rule.split('/');
let extendedRule = '';
const splittedRule = rule.split("/");
let extendedRule = "";
splittedRule.forEach((rulePart) => {
extendedRule += (extendedRule ? '/' : '') + rulePart;
extendedRule += (extendedRule ? "/" : "") + rulePart;
if (!extendedRules.includes(extendedRule)) {
extendedRules.push(extendedRule);
}
});
});

const hasRootConfigured = root && root !== '.';
const extendedRoot = `${process.cwd()}${hasRootConfigured ? `/${root}` : ''}`;
const hasRootConfigured = root && root !== ".";
const extendedRoot = `${posixSeparatedCwd()}${
hasRootConfigured ? `/${root}` : ""
}`;
const extendedRulesWithRoot = extendedRules.map(
(rule) => (extendedRoot ? `${extendedRoot}/` : '') + rule
(rule) => (extendedRoot ? `${extendedRoot}/` : "") + rule
);

return {
root: extendedRoot,
rules: [...extendedRulesWithRoot, extendedRoot]
rules: [...extendedRulesWithRoot, extendedRoot],
};
};

const isPathMatchRule = (path, rule) => {
const splittedPath = path.split('/');
const splittedRule = rule.split('/');
const splittedPath = path.split("/");
const splittedRule = rule.split("/");

if (rule.includes('**')) {
const [specifiedPath] = rule.split('/**');
if (rule.includes("**")) {
const [specifiedPath] = rule.split("/**");
return path.substr(0, specifiedPath.length) === specifiedPath;
}

if (splittedPath.length !== splittedRule.length) {
return false;
}
return splittedRule.reduce((acc, rulePart, i) => {
const isPermitted = rulePart !== '*' ? rulePart === splittedPath[i] : true;
const isPermitted = rulePart !== "*" ? rulePart === splittedPath[i] : true;
return acc && isPermitted;
}, true);
};
Expand All @@ -50,5 +54,5 @@ const checkPath = (path, rules) => {

module.exports = {
getExtendedRules,
checkPath
checkPath,
};