@dineroregnskab/eslint-plugin-custom-rules 1.0.7 → 2.0.0
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 +62 -0
- package/eslint-plugin-custom-rules.js +8 -2
- package/package.json +2 -5
- package/rules/camel-case-attributes.js +30 -0
package/README.md
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# Dinero custom ESLint rules
|
|
2
|
+
|
|
3
|
+
Custom extended rules for various Dinero specific standards & conventions.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Bundled with dinero.Frontend & dinero.Admin package.json, so a general npm install will include it as default.
|
|
8
|
+
|
|
9
|
+
Explicit install:
|
|
10
|
+
```bash
|
|
11
|
+
npm install @dineroregnskab/eslint-plugin-eslint-custom-rules@latest --save-dev
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Adding rules
|
|
15
|
+
|
|
16
|
+
Add the rule here:
|
|
17
|
+
|
|
18
|
+
`dinero-web-2.0/Dinero.Packages/Dinero.eslintCustomRules/rules`
|
|
19
|
+
|
|
20
|
+
You can test the rule by adding some code to test it on here.
|
|
21
|
+
|
|
22
|
+
`dinero-web-2.0/Dinero.Packages/Dinero.eslintCustomRules/example`
|
|
23
|
+
|
|
24
|
+
And run:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npx eslint test.ts
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### Publish & install new rule locally
|
|
31
|
+
|
|
32
|
+
Run:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
npm patch
|
|
36
|
+
```
|
|
37
|
+
```bash
|
|
38
|
+
npm publish
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
- In dinero.Frontend and/or dinero.Admin, update the root `package.json` file with the newly published version number.
|
|
42
|
+
- Locate the `eslintrc` file and add the new rule in the rules property (under `"files": ["*.html"]`, `"files": ["*.ts"]` etc. respectively).
|
|
43
|
+
> **Note: The reference here must be in the format of the package name without "eslint-plugin" + rule name**
|
|
44
|
+
|
|
45
|
+
Example:
|
|
46
|
+
|
|
47
|
+
`"@dineroregnskab/custom-rules/reducers-should-always-return": ["warn"]`
|
|
48
|
+
|
|
49
|
+
- Run
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
npm i
|
|
53
|
+
````
|
|
54
|
+
|
|
55
|
+
> **Note: You might need to restart the IDE for the new rule to apply**
|
|
56
|
+
|
|
57
|
+
#
|
|
58
|
+
See [ESLint custom rule tutorial](https://eslint.org/docs/latest/extend/custom-rule-tutorial) for more.
|
|
59
|
+
|
|
60
|
+
## License
|
|
61
|
+
|
|
62
|
+
[MIT](https://choosealicense.com/licenses/mit/)
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
const returnReducerRule = require('./rules/reducers-should-always-return');
|
|
2
|
+
const camelCaseRule = require('./rules/camel-case');
|
|
2
3
|
|
|
3
|
-
const customRulesplugin = {
|
|
4
|
-
|
|
4
|
+
const customRulesplugin = {
|
|
5
|
+
rules: {
|
|
6
|
+
'reducers-should-always-return': returnReducerRule,
|
|
7
|
+
'attr-camel-case-rule': camelCaseRule,
|
|
8
|
+
},
|
|
9
|
+
};
|
|
5
10
|
|
|
11
|
+
module.exports = customRulesplugin;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dineroregnskab/eslint-plugin-custom-rules",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "ESLint plugin with custom rules for Dineroregnskab",
|
|
5
5
|
"main": "eslint-plugin-custom-rules.js",
|
|
6
6
|
"scripts": {
|
|
@@ -18,8 +18,5 @@
|
|
|
18
18
|
"files": [
|
|
19
19
|
"**/*",
|
|
20
20
|
"!example/**/*"
|
|
21
|
-
]
|
|
22
|
-
"dependencies": {
|
|
23
|
-
"esquery": "^1.5.0"
|
|
24
|
-
}
|
|
21
|
+
]
|
|
25
22
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
meta: {
|
|
3
|
+
type: 'problem',
|
|
4
|
+
docs: {
|
|
5
|
+
description: 'Enforce camel case for data-cy and id attributes',
|
|
6
|
+
category: 'Possible Errors',
|
|
7
|
+
},
|
|
8
|
+
fixable: 'code',
|
|
9
|
+
schema: [],
|
|
10
|
+
},
|
|
11
|
+
|
|
12
|
+
create(context) {
|
|
13
|
+
return {
|
|
14
|
+
'VAttribute[directive=false][key.name="data-cy"], VAttribute[directive=false][key.name="id"]': function (node) {
|
|
15
|
+
const value = node.value && node.value.value;
|
|
16
|
+
const camelCasedValue = value.replace(/-([a-z])/g, function (g) { return g[1].toUpperCase(); });
|
|
17
|
+
|
|
18
|
+
if (value !== camelCasedValue) {
|
|
19
|
+
context.report({
|
|
20
|
+
node,
|
|
21
|
+
message: 'The value of data-cy and id attributes must be in camelCase.',
|
|
22
|
+
fix(fixer) {
|
|
23
|
+
return fixer.replaceText(node.value, `"${camelCasedValue}"`);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
},
|
|
30
|
+
};
|