@mimik/eslint-plugin-document-env 1.0.6 → 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 +10 -8
- package/eslint.config.js +52 -0
- package/index.js +25 -21
- package/package.json +22 -10
- package/rollup.config.js +14 -0
package/README.md
CHANGED
|
@@ -6,15 +6,17 @@
|
|
|
6
6
|
npm install @mimik/eslint-plugin-document-env
|
|
7
7
|
```
|
|
8
8
|
|
|
9
|
-
In your
|
|
9
|
+
In your `eslint.config.js`:
|
|
10
|
+
|
|
11
|
+
```js
|
|
12
|
+
import processDoc from '@mimik/eslint-plugin-document-env';
|
|
10
13
|
|
|
11
|
-
```json
|
|
12
14
|
{
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
plugins: {
|
|
16
|
+
processDoc,
|
|
17
|
+
},
|
|
18
|
+
rules: {
|
|
19
|
+
processDoc/validate-document-env: ['error']
|
|
18
20
|
}
|
|
19
21
|
}
|
|
20
22
|
```
|
|
@@ -24,7 +26,7 @@ An [eslint](https://github.com/eslint/eslint) plugin that ...
|
|
|
24
26
|
|
|
25
27
|
### `document-env/validate-document-env`
|
|
26
28
|
|
|
27
|
-
Verifies that when an environment variable is used, there is a
|
|
29
|
+
Verifies that when an environment variable is used, there is a documentation about it after the following header:
|
|
28
30
|
* | Env variable name | Description | Default | Comments |
|
|
29
31
|
* | ----------------- | ----------- | ------- | -------- |
|
|
30
32
|
|
package/eslint.config.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import importPlugin from 'eslint-plugin-import';
|
|
2
|
+
import js from '@eslint/js';
|
|
3
|
+
import stylistic from '@stylistic/eslint-plugin';
|
|
4
|
+
|
|
5
|
+
const MAX_LENGTH_LINE = 180;
|
|
6
|
+
const MAX_FUNCTION_PARAMETERS = 6;
|
|
7
|
+
const MAX_LINES_IN_FILES = 400;
|
|
8
|
+
const MAX_LINES_IN_FUNCTION = 100;
|
|
9
|
+
const MAX_STATEMENTS_IN_FUNCTION = 40;
|
|
10
|
+
const MIN_KEYS_IN_OBJECT = 10;
|
|
11
|
+
|
|
12
|
+
export default [
|
|
13
|
+
{
|
|
14
|
+
ignores: ['mochawesome-report/**', 'node_modules/**', 'dist/**'],
|
|
15
|
+
},
|
|
16
|
+
importPlugin.flatConfigs.recommended,
|
|
17
|
+
stylistic.configs['recommended-flat'],
|
|
18
|
+
js.configs.all,
|
|
19
|
+
{
|
|
20
|
+
languageOptions: {
|
|
21
|
+
ecmaVersion: 2022,
|
|
22
|
+
globals: {
|
|
23
|
+
console: 'readonly',
|
|
24
|
+
describe: 'readonly',
|
|
25
|
+
it: 'readonly',
|
|
26
|
+
require: 'readonly',
|
|
27
|
+
},
|
|
28
|
+
sourceType: 'module',
|
|
29
|
+
},
|
|
30
|
+
rules: {
|
|
31
|
+
'@stylistic/brace-style': ['warn', 'stroustrup', { allowSingleLine: true }],
|
|
32
|
+
'@stylistic/semi': ['error', 'always'],
|
|
33
|
+
'capitalized-comments': ['off'],
|
|
34
|
+
'curly': ['off'],
|
|
35
|
+
'import/no-extraneous-dependencies': ['error', { devDependencies: true }],
|
|
36
|
+
'import/no-unresolved': ['error', { amd: true, caseSensitiveStrict: true, commonjs: true }],
|
|
37
|
+
'init-declarations': ['off'],
|
|
38
|
+
'linebreak-style': ['off'],
|
|
39
|
+
'max-len': ['warn', MAX_LENGTH_LINE, { ignoreComments: true }],
|
|
40
|
+
'max-lines': ['warn', MAX_LINES_IN_FILES],
|
|
41
|
+
'max-lines-per-function': ['warn', MAX_LINES_IN_FUNCTION],
|
|
42
|
+
'max-params': ['error', MAX_FUNCTION_PARAMETERS],
|
|
43
|
+
'max-statements': ['warn', MAX_STATEMENTS_IN_FUNCTION],
|
|
44
|
+
'no-confusing-arrow': ['off'], // arrow isnt confusing
|
|
45
|
+
'no-inline-comments': ['off'],
|
|
46
|
+
'no-process-env': ['error'],
|
|
47
|
+
'one-var': ['error', 'never'],
|
|
48
|
+
'quotes': ['warn', 'single'],
|
|
49
|
+
'sort-keys': ['error', 'asc', { caseSensitive: true, minKeys: MIN_KEYS_IN_OBJECT, natural: false }],
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
];
|
package/index.js
CHANGED
|
@@ -1,23 +1,11 @@
|
|
|
1
1
|
const HEADER = ' * | Env variable name | Description | Default | Comments |\n';
|
|
2
2
|
const LINE = ' * | ----------------- | ----------- | ------- | -------- |\n';
|
|
3
|
-
|
|
3
|
+
const SINGLE = 1;
|
|
4
|
+
const NO_DESCRIPTION = 2;
|
|
5
|
+
|
|
6
|
+
const plugin = {
|
|
4
7
|
rules: {
|
|
5
8
|
'validate-document-env': {
|
|
6
|
-
meta: {
|
|
7
|
-
type: 'problem',
|
|
8
|
-
docs: {
|
|
9
|
-
description: 'validate document for environment variables',
|
|
10
|
-
category: 'Node.js and CommonJS',
|
|
11
|
-
recommended: false,
|
|
12
|
-
},
|
|
13
|
-
schema: [],
|
|
14
|
-
messages: {
|
|
15
|
-
unDesribedProcessEnv: 'Undescribed environement variable: {{ name }}',
|
|
16
|
-
unDocumentedProcessEnv: 'Undocumented environment variable: {{ name }}',
|
|
17
|
-
duplicatedProcessEnv: 'Duplicated definition for environment variable: {{ name }}',
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
|
|
21
9
|
create(context) {
|
|
22
10
|
return {
|
|
23
11
|
MemberExpression(node) {
|
|
@@ -26,12 +14,12 @@ module.exports = {
|
|
|
26
14
|
|
|
27
15
|
if (objectName === 'process' && !node.computed && propertyName && propertyName === 'env') {
|
|
28
16
|
if (node.parent && node.parent.property) {
|
|
29
|
-
const allComments = context.
|
|
17
|
+
const allComments = context.getSourceCode().ast.comments;
|
|
30
18
|
let foundDocument = false;
|
|
31
19
|
let propName = node.parent.property.name;
|
|
32
20
|
|
|
33
21
|
if (!propName) propName = context.getSourceCode().text.substring(node.parent.property.start, node.parent.property.end);
|
|
34
|
-
const reg = new RegExp(`^ \\* \\| (${propName.replace(/[|\\{}()[\]^$+*?.]/
|
|
22
|
+
const reg = new RegExp(`^ \\* \\| (${propName.replace(/[|\\{}()[\]^$+*?.]/gu, '\\$&')}) \\| *([^\\|]*)/u`, 'mgu');
|
|
35
23
|
|
|
36
24
|
allComments.forEach((comment) => {
|
|
37
25
|
if (!foundDocument && comment.type === 'Block' && comment.value.includes(HEADER) && comment.value.includes(LINE)) {
|
|
@@ -39,20 +27,36 @@ module.exports = {
|
|
|
39
27
|
|
|
40
28
|
if (match) {
|
|
41
29
|
foundDocument = true;
|
|
42
|
-
if (match.length >
|
|
30
|
+
if (match.length > SINGLE) context.report({ data: { name: propName }, messageId: 'duplicatedProcessEnv', node });
|
|
43
31
|
else {
|
|
44
32
|
match = reg.exec(comment.value);
|
|
45
|
-
if (!match[
|
|
33
|
+
if (!match[NO_DESCRIPTION]) context.report({ data: { name: propName }, messageId: 'unDesribedProcessEnv', node });
|
|
46
34
|
}
|
|
47
35
|
}
|
|
48
36
|
}
|
|
49
37
|
});
|
|
50
|
-
if (!foundDocument) context.report({
|
|
38
|
+
if (!foundDocument) context.report({ data: { name: propName }, messageId: 'unDocumentedProcessEnv', node });
|
|
51
39
|
}
|
|
52
40
|
}
|
|
53
41
|
},
|
|
54
42
|
};
|
|
55
43
|
},
|
|
44
|
+
meta: {
|
|
45
|
+
docs: {
|
|
46
|
+
category: 'Node.js',
|
|
47
|
+
description: 'Validate document for environment variables',
|
|
48
|
+
recommended: false,
|
|
49
|
+
},
|
|
50
|
+
messages: {
|
|
51
|
+
duplicatedProcessEnv: 'Duplicated definition for environment variable: {{ name }}',
|
|
52
|
+
unDesribedProcessEnv: 'Undescribed environment variable: {{ name }}',
|
|
53
|
+
unDocumentedProcessEnv: 'Undocumented environment variable: {{ name }}',
|
|
54
|
+
},
|
|
55
|
+
schema: [],
|
|
56
|
+
type: 'problem',
|
|
57
|
+
},
|
|
56
58
|
},
|
|
57
59
|
},
|
|
58
60
|
};
|
|
61
|
+
|
|
62
|
+
export default plugin;
|
package/package.json
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mimik/eslint-plugin-document-env",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "validation of environement variable documentation",
|
|
5
|
-
"main": "index.js",
|
|
5
|
+
"main": "./dist/index.cjs.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"module": "./index.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"require": "./dist/index.cjs.js",
|
|
11
|
+
"import": "./index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
6
14
|
"keywords": [
|
|
7
15
|
"eslint",
|
|
8
16
|
"eslint-plugin",
|
|
@@ -20,16 +28,20 @@
|
|
|
20
28
|
"url": "https://bitbucket.org/mimiktech/eslit-plugin-document-env"
|
|
21
29
|
},
|
|
22
30
|
"scripts": {
|
|
23
|
-
"lint": "eslint --
|
|
31
|
+
"lint": "eslint . --no-error-on-unmatched-pattern",
|
|
24
32
|
"test": "echo \"Error: no test specified\" && exit 0",
|
|
25
|
-
|
|
33
|
+
"prepublishOnly": "npm run lint && npm run test && npm run build",
|
|
34
|
+
"build": "rollup -c"
|
|
26
35
|
},
|
|
27
36
|
"devDependencies": {
|
|
28
|
-
"eslint": "
|
|
29
|
-
"eslint-
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"eslint-plugin
|
|
37
|
+
"@eslint/js": "9.17.0",
|
|
38
|
+
"@mimik/eslint-plugin-document-env": "1.0.6",
|
|
39
|
+
"@rollup/plugin-commonjs": "^28.0.2",
|
|
40
|
+
"@rollup/plugin-node-resolve": "^16.0.0",
|
|
41
|
+
"@rollup/plugin-terser": "0.4.4",
|
|
42
|
+
"@stylistic/eslint-plugin": "2.12.1",
|
|
43
|
+
"eslint": "9.17.0",
|
|
44
|
+
"eslint-plugin-import": "2.31.0",
|
|
45
|
+
"rollup": "^2.79.2"
|
|
34
46
|
}
|
|
35
47
|
}
|
package/rollup.config.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import commonjs from '@rollup/plugin-commonjs';
|
|
2
|
+
import resolve from '@rollup/plugin-node-resolve';
|
|
3
|
+
import terser from '@rollup/plugin-terser';
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
input: './index.js', // Entry point
|
|
7
|
+
output: [
|
|
8
|
+
{
|
|
9
|
+
file: './dist/index.cjs.js',
|
|
10
|
+
format: 'cjs',
|
|
11
|
+
},
|
|
12
|
+
],
|
|
13
|
+
plugins: [resolve(), commonjs(), terser()],
|
|
14
|
+
};
|