@dineroregnskab/eslint-plugin-custom-rules 1.0.4 → 1.0.6
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,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dineroregnskab/eslint-plugin-custom-rules",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "ESLint plugin with custom rules for Dineroregnskab",
|
|
5
5
|
"main": "eslint-plugin-custom-rules.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"test": "
|
|
7
|
+
"test": ""
|
|
8
8
|
},
|
|
9
9
|
"keywords": [],
|
|
10
10
|
"author": "",
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
meta: {
|
|
3
|
+
type: 'problem',
|
|
4
|
+
docs: {
|
|
5
|
+
description:
|
|
6
|
+
'Enforce that a ngrx reducer always returns a value, so the store state remains intact.',
|
|
7
|
+
},
|
|
8
|
+
fixable: 'code',
|
|
9
|
+
schema: [],
|
|
10
|
+
},
|
|
11
|
+
|
|
12
|
+
create(context) {
|
|
13
|
+
return {
|
|
14
|
+
'CallExpression[callee.name="createReducer"]': function (node) {
|
|
15
|
+
node.arguments.forEach(function (arg) {
|
|
16
|
+
if (
|
|
17
|
+
arg.type === 'CallExpression' &&
|
|
18
|
+
arg.callee.name === 'on'
|
|
19
|
+
) {
|
|
20
|
+
arg.arguments.slice(1).forEach(function (handler) {
|
|
21
|
+
const isFunction =
|
|
22
|
+
handler.type === 'FunctionExpression' ||
|
|
23
|
+
handler.type === 'ArrowFunctionExpression';
|
|
24
|
+
const isBlockStatement =
|
|
25
|
+
handler.body.type === 'BlockStatement';
|
|
26
|
+
const hasNoReturn =
|
|
27
|
+
isBlockStatement &&
|
|
28
|
+
!handler.body.body.some(
|
|
29
|
+
(statement) =>
|
|
30
|
+
statement.type === 'ReturnStatement',
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
if (isFunction && isBlockStatement && hasNoReturn) {
|
|
34
|
+
context.report({
|
|
35
|
+
node: handler,
|
|
36
|
+
message:
|
|
37
|
+
'Reducer function must return a value to avoid undefined state.',
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
},
|
|
46
|
+
};
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
meta: {
|
|
3
|
-
type: "problem",
|
|
4
|
-
docs: {
|
|
5
|
-
description: "Enforce that a ngrx reducer always returns a value, so the store state remains intact.",
|
|
6
|
-
},
|
|
7
|
-
fixable: "code",
|
|
8
|
-
schema: []
|
|
9
|
-
},
|
|
10
|
-
|
|
11
|
-
create: function(context) {
|
|
12
|
-
return {
|
|
13
|
-
'CallExpression[callee.name="createReducer"]': function(node) {
|
|
14
|
-
node.arguments.forEach(function(arg) {
|
|
15
|
-
if (arg.type === 'CallExpression' && arg.callee.name === 'on') {
|
|
16
|
-
arg.arguments.slice(1).forEach(function(handler) {
|
|
17
|
-
const isFunction = handler.type === 'FunctionExpression' || handler.type === 'ArrowFunctionExpression';
|
|
18
|
-
const isBlockStatement = handler.body.type === 'BlockStatement';
|
|
19
|
-
const hasNoReturn = isBlockStatement && !handler.body.body.some(statement => statement.type === 'ReturnStatement');
|
|
20
|
-
|
|
21
|
-
if (isFunction && isBlockStatement && hasNoReturn) {
|
|
22
|
-
context.report({
|
|
23
|
-
node: handler,
|
|
24
|
-
message: 'Reducer function must return a value to avoid undefined state.'
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
// tilføj fixer?
|
|
36
|
-
// tilføj lint til filerne her
|
|
37
|
-
// convert til ts?
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
// readme med guide til tilføjelse af regel (+ version patch & publish, adding the rule to html/ts, nameing, adding to projects (main app/admin))
|