eslint-config-matsuri 1.6.1 → 1.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +1 -6
- package/package.json +4 -6
- package/rules/naming-convention.js +0 -146
package/index.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
const rulesDirPlugin = require("eslint-plugin-rulesdir");
|
|
2
|
-
rulesDirPlugin.RULES_DIR = __dirname + "/rules";
|
|
3
|
-
|
|
4
1
|
/** @type {import('eslint').Linter.BaseConfig} */
|
|
5
2
|
const config = {
|
|
6
3
|
reportUnusedDisableDirectives: true,
|
|
@@ -13,10 +10,8 @@ const config = {
|
|
|
13
10
|
ecmaVersion: 12,
|
|
14
11
|
},
|
|
15
12
|
extends: ["eslint:recommended"],
|
|
16
|
-
plugins: ["sort-imports-es6-autofix"
|
|
13
|
+
plugins: ["sort-imports-es6-autofix"],
|
|
17
14
|
rules: {
|
|
18
|
-
"rulesdir/naming-convention": ["error", { fixable: false }],
|
|
19
|
-
|
|
20
15
|
"no-console": ["error", { allow: ["error"] }],
|
|
21
16
|
eqeqeq: ["error", "always"],
|
|
22
17
|
|
package/package.json
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-config-matsuri",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"files": [
|
|
7
|
-
"index.js"
|
|
8
|
-
"rules"
|
|
7
|
+
"index.js"
|
|
9
8
|
],
|
|
10
9
|
"scripts": {
|
|
11
10
|
"test": "eslint . --max-warnings 0"
|
|
@@ -16,7 +15,7 @@
|
|
|
16
15
|
"registry": "https://registry.npmjs.org/"
|
|
17
16
|
},
|
|
18
17
|
"peerDependencies": {
|
|
19
|
-
"eslint": "
|
|
18
|
+
"eslint": "8.38.0"
|
|
20
19
|
},
|
|
21
20
|
"devDependencies": {
|
|
22
21
|
"@emotion/react": "11.10.5",
|
|
@@ -33,8 +32,7 @@
|
|
|
33
32
|
"eslint-plugin-jsx-a11y": "6.7.1",
|
|
34
33
|
"eslint-plugin-react": "7.32.2",
|
|
35
34
|
"eslint-plugin-react-hooks": "4.6.0",
|
|
36
|
-
"eslint-plugin-
|
|
37
|
-
"eslint-plugin-sort-imports-es6-autofix": "^0.6.0",
|
|
35
|
+
"eslint-plugin-sort-imports-es6-autofix": "0.6.0",
|
|
38
36
|
"eslint-plugin-unused-imports": "2.0.0"
|
|
39
37
|
}
|
|
40
38
|
}
|
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
const REGEX_CAMEL_CASE = /^[a-z][a-zA-Z0-9]*$/;
|
|
2
|
-
const REGEX_PASCAL_CASE = /^[A-Z][a-zA-Z0-9]*$/;
|
|
3
|
-
const REGEX_UPPER_CASE = /^[A-Z][A-Z0-9_]*$/;
|
|
4
|
-
const REGEX_SNAKE_CASE = /^[a-z][a-z0-9_]*$/;
|
|
5
|
-
|
|
6
|
-
const isCamelCase = (name) => REGEX_CAMEL_CASE.test(name);
|
|
7
|
-
const isPascalCase = (name) => REGEX_PASCAL_CASE.test(name);
|
|
8
|
-
const isUpperCase = (name) => REGEX_UPPER_CASE.test(name);
|
|
9
|
-
const isSnakeCase = (name) => REGEX_SNAKE_CASE.test(name);
|
|
10
|
-
|
|
11
|
-
const toCamelCase = (name) => {
|
|
12
|
-
if (isCamelCase(name)) {
|
|
13
|
-
return name;
|
|
14
|
-
}
|
|
15
|
-
if (isPascalCase(name)) {
|
|
16
|
-
return name[0].toLowerCase() + name.slice(1);
|
|
17
|
-
}
|
|
18
|
-
if (isUpperCase(name) || isSnakeCase(name)) {
|
|
19
|
-
const tmp = name
|
|
20
|
-
.split("_")
|
|
21
|
-
.map((word) => word[0].toUpperCase() + word.slice(1))
|
|
22
|
-
.join("");
|
|
23
|
-
return tmp[0].toLowerCase() + tmp.slice(1);
|
|
24
|
-
}
|
|
25
|
-
return name;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const checkValidity = (name, format) => {
|
|
29
|
-
switch (format) {
|
|
30
|
-
case "camelCase": {
|
|
31
|
-
return isCamelCase(name);
|
|
32
|
-
}
|
|
33
|
-
case "PascalCase": {
|
|
34
|
-
return isPascalCase(name);
|
|
35
|
-
}
|
|
36
|
-
case "UPPER_CASE": {
|
|
37
|
-
return isUpperCase(name);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
const trimUnderscore = (name, leadingUnderscore, trailingUnderscore) => {
|
|
43
|
-
if (leadingUnderscore === "allow" && name?.startsWith("_")) {
|
|
44
|
-
return name.slice(1);
|
|
45
|
-
}
|
|
46
|
-
if (trailingUnderscore === "allow" && name?.endsWith("_")) {
|
|
47
|
-
return name.slice(0, -1);
|
|
48
|
-
}
|
|
49
|
-
return name;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* @typedef Option
|
|
54
|
-
* @property {string[]} format
|
|
55
|
-
* @property {string} fix
|
|
56
|
-
* @property {string} leadingUnderscore
|
|
57
|
-
* @property {string} trailingUnderscore
|
|
58
|
-
*/
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* @param {Option} option
|
|
62
|
-
* @param {boolean} fixable
|
|
63
|
-
*/
|
|
64
|
-
const reportValidity = (context, node, option, fixable) => {
|
|
65
|
-
const { format, fix, leadingUnderscore, trailingUnderscore } = option;
|
|
66
|
-
if (node.id === null) {
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
const valid = format.some((format) => {
|
|
70
|
-
const name = trimUnderscore(
|
|
71
|
-
node.id.name,
|
|
72
|
-
leadingUnderscore,
|
|
73
|
-
trailingUnderscore
|
|
74
|
-
);
|
|
75
|
-
return checkValidity(name, format);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
if (valid === false) {
|
|
79
|
-
context.report({
|
|
80
|
-
node,
|
|
81
|
-
message: `${node.id.name} must be ${format.join(" or ")}`,
|
|
82
|
-
fix: fixable
|
|
83
|
-
? (fixer) => {
|
|
84
|
-
switch (fix) {
|
|
85
|
-
case "camelCase": {
|
|
86
|
-
return fixer.replaceText(node.id, toCamelCase(node.id.name));
|
|
87
|
-
}
|
|
88
|
-
default: {
|
|
89
|
-
return fixer.replaceText(node.id, node.id.name);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
: null,
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* @type {Object.<string, Option>}
|
|
100
|
-
*/
|
|
101
|
-
const options = {
|
|
102
|
-
validable: {
|
|
103
|
-
format: ["camelCase", "UPPER_CASE"],
|
|
104
|
-
fix: "camelCase",
|
|
105
|
-
leadingUnderscore: "allow",
|
|
106
|
-
trailingUnderscore: "allow",
|
|
107
|
-
},
|
|
108
|
-
function: {
|
|
109
|
-
format: ["camelCase", "PascalCase"],
|
|
110
|
-
fix: "camelCase",
|
|
111
|
-
leadingUnderscore: "allow",
|
|
112
|
-
trailingUnderscore: "allow",
|
|
113
|
-
},
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* @type {import("eslint").Rule.RuleModule}
|
|
118
|
-
*/
|
|
119
|
-
const rule = {
|
|
120
|
-
meta: {
|
|
121
|
-
type: "problem",
|
|
122
|
-
fixable: "code",
|
|
123
|
-
hasSuggestions: true
|
|
124
|
-
},
|
|
125
|
-
create: (context) => {
|
|
126
|
-
const fixable = context.options[0]?.fixable ?? false;
|
|
127
|
-
|
|
128
|
-
return {
|
|
129
|
-
VariableDeclarator: (node) => {
|
|
130
|
-
if (node.init?.type === "ArrowFunctionExpression") {
|
|
131
|
-
reportValidity(context, node, options.function, fixable);
|
|
132
|
-
} else {
|
|
133
|
-
reportValidity(context, node, options.validable, fixable);
|
|
134
|
-
}
|
|
135
|
-
},
|
|
136
|
-
FunctionDeclaration: (node) => {
|
|
137
|
-
reportValidity(context, node, options.function, fixable);
|
|
138
|
-
},
|
|
139
|
-
FunctionExpression: (node) => {
|
|
140
|
-
reportValidity(context, node, options.function, fixable);
|
|
141
|
-
},
|
|
142
|
-
};
|
|
143
|
-
},
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
module.exports = rule;
|