@mimik/eslint-plugin-document-env 1.0.6 → 2.0.1
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/.eslintrc +34 -0
- package/eslint.config.js +52 -0
- package/index.js +25 -21
- package/package.json +21 -18
package/.eslintrc
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"env": {
|
|
3
|
+
"node": true
|
|
4
|
+
},
|
|
5
|
+
"parserOptions": {
|
|
6
|
+
"ecmaVersion": 2020
|
|
7
|
+
},
|
|
8
|
+
"extends": "airbnb",
|
|
9
|
+
"rules": {
|
|
10
|
+
"import/no-extraneous-dependencies": ["error", {"devDependencies": true}],
|
|
11
|
+
"brace-style": [1, "stroustrup", {"allowSingleLine": true}],
|
|
12
|
+
"no-confusing-arrow": [0], // arrow isnt confusing
|
|
13
|
+
"max-len": [1, 180, { "ignoreComments": true }],
|
|
14
|
+
"linebreak-style": 0,
|
|
15
|
+
"quotes": [1, "single"],
|
|
16
|
+
"semi": [1, "always"],
|
|
17
|
+
"no-process-env": ["error"]
|
|
18
|
+
},
|
|
19
|
+
"settings":{
|
|
20
|
+
"react": {
|
|
21
|
+
"version": "detect"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"globals": {
|
|
25
|
+
"module": true,
|
|
26
|
+
"require": true,
|
|
27
|
+
"const": false,
|
|
28
|
+
"it": false,
|
|
29
|
+
"describe": false,
|
|
30
|
+
"before": true,
|
|
31
|
+
"after": true,
|
|
32
|
+
"JSON": true
|
|
33
|
+
}
|
|
34
|
+
}
|
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,35 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mimik/eslint-plugin-document-env",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "validation of environement variable documentation",
|
|
5
|
-
"main": "index.js",
|
|
5
|
+
"main": "./index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"lint": "eslint . --no-error-on-unmatched-pattern",
|
|
9
|
+
"test": "echo \"Error: no test specified\" && exit 0",
|
|
10
|
+
"prepublishOnly": "npm run lint && npm run test"
|
|
11
|
+
},
|
|
12
|
+
"husky": {
|
|
13
|
+
"hooks": {
|
|
14
|
+
"pre-commit": "npm run commit-ready",
|
|
15
|
+
"pre-push": "npm run test"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
6
18
|
"keywords": [
|
|
19
|
+
"mimik",
|
|
7
20
|
"eslint",
|
|
8
21
|
"eslint-plugin",
|
|
9
22
|
"eslintplugin",
|
|
10
23
|
"process.env"
|
|
11
24
|
],
|
|
12
|
-
"license": "MIT",
|
|
13
|
-
"files": [
|
|
14
|
-
"README.md",
|
|
15
|
-
"*.js"
|
|
16
|
-
],
|
|
17
25
|
"author": "mimik technology inc <support@mimik.com> (https://developer.mimik.com/)",
|
|
26
|
+
"license": "MIT",
|
|
18
27
|
"repository": {
|
|
19
28
|
"type": "git",
|
|
20
29
|
"url": "https://bitbucket.org/mimiktech/eslit-plugin-document-env"
|
|
21
30
|
},
|
|
22
|
-
"scripts": {
|
|
23
|
-
"lint": "eslint --ignore-path .gitignore .",
|
|
24
|
-
"test": "echo \"Error: no test specified\" && exit 0",
|
|
25
|
-
"prepublishOnly": "npm run lint && npm run test"
|
|
26
|
-
},
|
|
27
31
|
"devDependencies": {
|
|
28
|
-
"eslint": "
|
|
29
|
-
"eslint-
|
|
30
|
-
"eslint
|
|
31
|
-
"eslint-plugin-
|
|
32
|
-
"
|
|
33
|
-
"eslint-plugin-react-hooks": "4.6.0"
|
|
32
|
+
"@eslint/js": "9.20.0",
|
|
33
|
+
"@stylistic/eslint-plugin": "3.1.0",
|
|
34
|
+
"eslint": "9.20.1",
|
|
35
|
+
"eslint-plugin-import": "2.31.0",
|
|
36
|
+
"husky": "9.1.7"
|
|
34
37
|
}
|
|
35
38
|
}
|