eslint-plugin-crisp 1.0.0 → 1.0.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-crisp",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Custom EsLint Rules for Crisp",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"author": "Crisp IM SAS",
|
|
@@ -8,6 +8,6 @@
|
|
|
8
8
|
"dependencies": {
|
|
9
9
|
"doctrine": "3.0.0",
|
|
10
10
|
"eslint": "8.45.0",
|
|
11
|
-
"eslint-plugin-jsdoc": "40.3.
|
|
11
|
+
"eslint-plugin-jsdoc": "40.3.0"
|
|
12
12
|
}
|
|
13
13
|
}
|
package/recommended.js
CHANGED
|
@@ -13,6 +13,7 @@ module.exports = {
|
|
|
13
13
|
"semi": ["error", "always"],
|
|
14
14
|
"max-len": ["error", 80],
|
|
15
15
|
"comma-dangle": ["error", "never"],
|
|
16
|
+
"arrow-parens": ["error", "always"],
|
|
16
17
|
"crisp/align-one-var": ["error"],
|
|
17
18
|
"crisp/multiline-comment-end-backslash": "error",
|
|
18
19
|
"crisp/const": "error",
|
|
@@ -25,11 +26,14 @@ module.exports = {
|
|
|
25
26
|
"crisp/one-space-after-operator": "error",
|
|
26
27
|
"crisp/no-trailing-spaces": "error",
|
|
27
28
|
"crisp/ternary-parenthesis": "error",
|
|
28
|
-
"crisp/variable-names": "error",
|
|
29
|
+
"crisp/variable-names": ["error", {
|
|
30
|
+
"variableExceptions": ["fn"]
|
|
31
|
+
}],
|
|
29
32
|
"crisp/jsdoc-match-params": ["error", { "exceptions": ["constructor"] }],
|
|
30
33
|
|
|
31
34
|
"crisp/constructor-variables": ["error", {
|
|
32
|
-
"
|
|
35
|
+
"filenameExceptions": ["app.js"],
|
|
36
|
+
"variableExceptions": ["client"]
|
|
33
37
|
}],
|
|
34
38
|
"jsdoc/require-jsdoc": ["error", {
|
|
35
39
|
"require": {
|
|
@@ -9,7 +9,11 @@ module.exports = {
|
|
|
9
9
|
{
|
|
10
10
|
type: "object",
|
|
11
11
|
properties: {
|
|
12
|
-
|
|
12
|
+
filenameExceptions: {
|
|
13
|
+
type: "array",
|
|
14
|
+
items: { type: "string" },
|
|
15
|
+
},
|
|
16
|
+
variableExceptions: {
|
|
13
17
|
type: "array",
|
|
14
18
|
items: { type: "string" },
|
|
15
19
|
},
|
|
@@ -21,13 +25,17 @@ module.exports = {
|
|
|
21
25
|
|
|
22
26
|
create(context) {
|
|
23
27
|
const options = context.options[0] || {};
|
|
24
|
-
const
|
|
28
|
+
const filename = context.getFilename();
|
|
29
|
+
const filenameExceptions = options.filenameExceptions || [];
|
|
30
|
+
const variableExceptions = options.variableExceptions || [];
|
|
31
|
+
|
|
32
|
+
const isFilenameException = filenameExceptions.some((exception) => filename.endsWith(exception));
|
|
25
33
|
|
|
26
34
|
return {
|
|
27
35
|
"MethodDefinition[kind='constructor'] > FunctionExpression > BlockStatement > ExpressionStatement > AssignmentExpression": function(node) {
|
|
28
|
-
if(node.left.type === "MemberExpression" && node.left.object.type === "ThisExpression"){
|
|
36
|
+
if(node.left.type === "MemberExpression" && node.left.object.type === "ThisExpression") {
|
|
29
37
|
const varName = node.left.property.name;
|
|
30
|
-
if (!varName.startsWith("_") && !
|
|
38
|
+
if (!varName.startsWith("_") && !isFilenameException && !variableExceptions.includes(varName)) {
|
|
31
39
|
context.report({
|
|
32
40
|
node,
|
|
33
41
|
message: "Class properties in the constructor should start with '_', except for specified exceptions",
|
|
@@ -2,7 +2,7 @@ module.exports = {
|
|
|
2
2
|
meta: {
|
|
3
3
|
type: "layout",
|
|
4
4
|
docs: {
|
|
5
|
-
description: "enforce
|
|
5
|
+
description: "enforce at least one space before and exactly one space after = and : assignment",
|
|
6
6
|
category: "Stylistic Issues",
|
|
7
7
|
recommended: false,
|
|
8
8
|
},
|
|
@@ -10,59 +10,37 @@ module.exports = {
|
|
|
10
10
|
schema: [], // no options
|
|
11
11
|
},
|
|
12
12
|
create(context) {
|
|
13
|
+
const sourceCode = context.getSourceCode();
|
|
14
|
+
|
|
15
|
+
const checkSpacing = (node, operatorToken, operatorName) => {
|
|
16
|
+
if (Math.abs(sourceCode.getTokenBefore(operatorToken).loc.end.column - operatorToken.loc.start.column) < 1 || sourceCode.getTokenAfter(operatorToken).loc.start.column - operatorToken.loc.end.column > 1) {
|
|
17
|
+
context.report({
|
|
18
|
+
node: operatorToken,
|
|
19
|
+
message: `There should be at least one space before and exactly one space after '${operatorName}'`,
|
|
20
|
+
fix(fixer) {
|
|
21
|
+
return fixer.replaceTextRange(
|
|
22
|
+
[sourceCode.getTokenBefore(operatorToken).range[1], sourceCode.getTokenAfter(operatorToken).range[0]],
|
|
23
|
+
` ${operatorName} `
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
13
30
|
return {
|
|
14
31
|
AssignmentExpression(node) {
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if (sourceCode.getTokenAfter(operator).loc.start.column - operator.loc.end.column > 1) {
|
|
19
|
-
context.report({
|
|
20
|
-
node: operator,
|
|
21
|
-
message: "There should be exactly one space after '=' operator",
|
|
22
|
-
fix(fixer) {
|
|
23
|
-
return fixer.replaceTextRange(
|
|
24
|
-
[operator.range[1], sourceCode.getTokenAfter(operator).range[0]],
|
|
25
|
-
" "
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
}
|
|
32
|
+
const operatorToken = sourceCode.getTokenBefore(node.right);
|
|
33
|
+
checkSpacing(node, operatorToken, '=');
|
|
30
34
|
},
|
|
31
35
|
VariableDeclarator(node) {
|
|
32
36
|
if (node.init) {
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (sourceCode.getTokenAfter(operator).loc.start.column - operator.loc.end.column > 1) {
|
|
37
|
-
context.report({
|
|
38
|
-
node: operator,
|
|
39
|
-
message: "There should be exactly one space after '=' operator",
|
|
40
|
-
fix(fixer) {
|
|
41
|
-
return fixer.replaceTextRange(
|
|
42
|
-
[operator.range[1], sourceCode.getTokenAfter(operator).range[0]],
|
|
43
|
-
" "
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
}
|
|
37
|
+
const operatorToken = sourceCode.getTokenBefore(node.init);
|
|
38
|
+
checkSpacing(node, operatorToken, '=');
|
|
48
39
|
}
|
|
49
40
|
},
|
|
50
41
|
Property(node) {
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (sourceCode.getTokenAfter(operator).loc.start.column - operator.loc.end.column > 1) {
|
|
55
|
-
context.report({
|
|
56
|
-
node: operator,
|
|
57
|
-
message: "There should be exactly one space after ':'' operator",
|
|
58
|
-
fix(fixer) {
|
|
59
|
-
return fixer.replaceTextRange(
|
|
60
|
-
[operator.range[1], sourceCode.getTokenAfter(operator).range[0]],
|
|
61
|
-
" "
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
}
|
|
42
|
+
const operatorToken = sourceCode.getTokenBefore(node.value);
|
|
43
|
+
checkSpacing(node, operatorToken, ':');
|
|
66
44
|
},
|
|
67
45
|
};
|
|
68
46
|
},
|
package/rules/variable-names.js
CHANGED
|
@@ -6,17 +6,30 @@ module.exports = {
|
|
|
6
6
|
category: "Stylistic Issues",
|
|
7
7
|
recommended: false,
|
|
8
8
|
},
|
|
9
|
-
schema: [
|
|
9
|
+
schema: [{
|
|
10
|
+
type: "object",
|
|
11
|
+
properties: {
|
|
12
|
+
variableExceptions: {
|
|
13
|
+
type: "array",
|
|
14
|
+
items: { type: "string" },
|
|
15
|
+
uniqueItems: true,
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
additionalProperties: false,
|
|
19
|
+
}], // options schema updated
|
|
10
20
|
},
|
|
11
21
|
create(context) {
|
|
22
|
+
const options = context.options[0] || {};
|
|
23
|
+
const variableExceptions = options.variableExceptions || [];
|
|
24
|
+
|
|
12
25
|
function checkDeclaration(node, body) {
|
|
13
26
|
body.body.forEach((statement) => {
|
|
14
27
|
if (statement.type === "VariableDeclaration") {
|
|
15
28
|
statement.declarations.forEach((declaration) => {
|
|
16
|
-
if (declaration.id.name && !declaration.id.name.startsWith("_")) {
|
|
29
|
+
if (declaration.id.name && !declaration.id.name.startsWith("_") && !variableExceptions.includes(declaration.id.name)) {
|
|
17
30
|
context.report({
|
|
18
31
|
node: declaration,
|
|
19
|
-
message:
|
|
32
|
+
message: `Variables defined within a method should start with '_' ({${declaration.id.name}})`,
|
|
20
33
|
});
|
|
21
34
|
}
|
|
22
35
|
});
|