@dineroregnskab/eslint-plugin-custom-rules 2.0.3 → 2.0.5
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/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Dinero
|
|
1
|
+
# Dinero Custom ESLint Rules
|
|
2
2
|
|
|
3
3
|
Custom extended rules for various Dinero specific standards & conventions.
|
|
4
4
|
|
|
@@ -15,11 +15,11 @@ npm install @dineroregnskab/eslint-plugin-eslint-custom-rules@latest --save-dev
|
|
|
15
15
|
|
|
16
16
|
Add the rule here:
|
|
17
17
|
|
|
18
|
-
`dinero-web-2.0/Dinero.Packages/Dinero.
|
|
18
|
+
`dinero-web-2.0/Dinero.Packages/Dinero.EslintCustomRules/rules`
|
|
19
19
|
|
|
20
20
|
You can test the rule by adding some code to test it on here.
|
|
21
21
|
|
|
22
|
-
`dinero-web-2.0/Dinero.Packages/Dinero.
|
|
22
|
+
`dinero-web-2.0/Dinero.Packages/Dinero.EslintCustomRules/example`
|
|
23
23
|
|
|
24
24
|
And run:
|
|
25
25
|
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
const returnReducerRule = require('./rules/reducers-should-always-return');
|
|
2
2
|
const camelCaseRule = require('./rules/camel-case-attributes');
|
|
3
3
|
|
|
4
|
-
const
|
|
4
|
+
const customRulesPlugin = {
|
|
5
5
|
rules: {
|
|
6
6
|
'reducers-should-always-return': returnReducerRule,
|
|
7
7
|
'attr-camel-case-rule': camelCaseRule,
|
|
8
8
|
},
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
-
module.exports =
|
|
11
|
+
module.exports = customRulesPlugin;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dineroregnskab/eslint-plugin-custom-rules",
|
|
3
|
-
"version": "2.0.
|
|
4
|
-
"description": "ESLint plugin with custom rules for
|
|
3
|
+
"version": "2.0.5",
|
|
4
|
+
"description": "ESLint plugin with custom rules for Dinero Regnskab",
|
|
5
5
|
"main": "eslint-plugin-custom-rules.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": ""
|
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
function hasReturnStatement(node) {
|
|
2
|
+
if (node.type === 'ReturnStatement') {
|
|
3
|
+
return true;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
if (node.type === 'BlockStatement') {
|
|
7
|
+
return node.body.some(hasReturnStatement);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
if (node.type === 'IfStatement') {
|
|
11
|
+
return (
|
|
12
|
+
hasReturnStatement(node.consequent) &&
|
|
13
|
+
(node.alternate !== null ? hasReturnStatement(node.alternate) : false)
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
|
|
1
20
|
module.exports = {
|
|
2
21
|
meta: {
|
|
3
22
|
type: 'problem',
|
|
@@ -25,10 +44,7 @@ module.exports = {
|
|
|
25
44
|
handler?.body?.type === 'BlockStatement';
|
|
26
45
|
const hasNoReturn =
|
|
27
46
|
isBlockStatement &&
|
|
28
|
-
!handler
|
|
29
|
-
(statement) =>
|
|
30
|
-
statement.type === 'ReturnStatement',
|
|
31
|
-
);
|
|
47
|
+
!hasReturnStatement(handler.body);
|
|
32
48
|
|
|
33
49
|
if (isFunction && isBlockStatement && hasNoReturn) {
|
|
34
50
|
context.report({
|