@gitlab/eslint-plugin 20.7.1 → 21.1.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.
@@ -0,0 +1,140 @@
1
+ const confusingBrowserGlobals = require('confusing-browser-globals');
2
+ const globals = require('globals');
3
+ const unicornPlugin = require('eslint-plugin-unicorn');
4
+ const promisePlugin = require('eslint-plugin-promise');
5
+ const importPlugin = require('eslint-plugin-import');
6
+
7
+ // Import all the base configurations
8
+ const bestPracticesConfig = require('./base/best-practices');
9
+ const errorsConfig = require('./base/errors');
10
+ const nodeConfig = require('./base/node');
11
+ const styleConfig = require('./base/style');
12
+ const variablesConfig = require('./base/variables');
13
+ const es6Config = require('./base/es6');
14
+ const importsConfig = require('./base/imports');
15
+ const strictConfig = require('./base/strict');
16
+
17
+ /*
18
+ This plugin contains rules related to GitLab JavaScript style guide
19
+ Vue specific rules are in lib/configs/vue.js
20
+ */
21
+ module.exports = {
22
+ languageOptions: {
23
+ globals: {
24
+ ...globals.browser,
25
+ ...globals.es2020,
26
+ ...globals.node,
27
+ ...globals.es6,
28
+ },
29
+ ecmaVersion: 'latest',
30
+ sourceType: 'module',
31
+ parserOptions: {
32
+ parser: 'espree',
33
+ },
34
+ },
35
+ plugins: {
36
+ unicorn: unicornPlugin,
37
+ promise: promisePlugin,
38
+ import: importPlugin,
39
+ },
40
+ settings: {
41
+ // Merge import settings from imports config
42
+ ...importsConfig.settings,
43
+ },
44
+ rules: {
45
+ ...promisePlugin.configs['flat/recommended'].rules,
46
+ // Merge all rules from the base configurations
47
+ ...bestPracticesConfig.rules,
48
+ ...errorsConfig.rules,
49
+ ...nodeConfig.rules,
50
+ ...styleConfig.rules,
51
+ ...variablesConfig.rules,
52
+ ...es6Config.rules,
53
+ ...importsConfig.rules,
54
+ ...strictConfig.rules,
55
+ // Override specific rules from base configs
56
+ // Promise rule customizations
57
+ 'promise/catch-or-return': [
58
+ 'error',
59
+ {
60
+ allowFinally: true,
61
+ },
62
+ ],
63
+ camelcase: [
64
+ 'error',
65
+ {
66
+ properties: 'never',
67
+ ignoreDestructuring: true,
68
+ },
69
+ ],
70
+ 'default-param-last': 'off',
71
+ 'arrow-body-style': 'off',
72
+ 'unicorn/filename-case': ['error', { case: 'snakeCase' }],
73
+ 'unicorn/no-array-callback-reference': 'error',
74
+ 'import/prefer-default-export': 'off',
75
+ 'import/no-default-export': 'error',
76
+ 'import/no-deprecated': 'error',
77
+ 'import/no-dynamic-require': ['error', { esmodule: true }],
78
+ 'no-implicit-coercion': [
79
+ 'error',
80
+ {
81
+ boolean: true,
82
+ number: true,
83
+ string: true,
84
+ },
85
+ ],
86
+ 'no-param-reassign': [
87
+ 'error',
88
+ {
89
+ props: true,
90
+ ignorePropertyModificationsFor: ['acc', 'accumulator', 'el', 'element', 'state'],
91
+ },
92
+ ],
93
+ 'no-restricted-exports': [
94
+ 'error',
95
+ {
96
+ restrictedNamedExports: [
97
+ 'then', // avoid confusion when used with dynamic `import()` promise
98
+ ],
99
+ },
100
+ ],
101
+ 'no-restricted-syntax': 'off',
102
+ 'no-sequences': [
103
+ 'error',
104
+ {
105
+ allowInParentheses: false,
106
+ },
107
+ ],
108
+ 'no-restricted-globals': [
109
+ 'error',
110
+ {
111
+ name: 'isFinite',
112
+ message:
113
+ 'Use Number.isFinite instead https://github.com/airbnb/javascript#standard-library--isfinite',
114
+ },
115
+ {
116
+ name: 'isNaN',
117
+ message:
118
+ 'Use Number.isNaN instead https://github.com/airbnb/javascript#standard-library--isnan',
119
+ },
120
+ {
121
+ name: 'escape',
122
+ message:
123
+ "The global `escape` function is unsafe. Did you mean to use `encodeURI`, `encodeURIComponent` or lodash's `escape` instead?",
124
+ },
125
+ {
126
+ name: 'unescape',
127
+ message:
128
+ "The global `unescape` function is unsafe. Did you mean to use `decodeURI`, `decodeURIComponent` or lodash's `unescape` instead?",
129
+ },
130
+ ].concat(confusingBrowserGlobals),
131
+ 'import/order': [
132
+ 'error',
133
+ {
134
+ groups: ['builtin', 'external', 'internal', 'parent', 'sibling', 'index'],
135
+ },
136
+ ],
137
+ // https://docs.gitlab.com/ee/development/fe_guide/style/javascript.html#limit-number-of-parameters
138
+ 'max-params': ['error', { max: 3 }],
139
+ },
140
+ };
@@ -0,0 +1,134 @@
1
+ const baseConfig = require('./base');
2
+ const tsEslint = require('@typescript-eslint/eslint-plugin');
3
+ const tsParser = require('@typescript-eslint/parser');
4
+ const globals = require('globals');
5
+
6
+ const tsConfig = [
7
+ {
8
+ languageOptions: {
9
+ globals: {
10
+ ...baseConfig.languageOptions.globals,
11
+ ...globals.mocha,
12
+ ...globals.jest,
13
+ },
14
+ ecmaVersion: baseConfig.languageOptions.ecmaVersion,
15
+ sourceType: baseConfig.languageOptions.sourceType,
16
+ parserOptions: baseConfig.languageOptions.parserOptions || {},
17
+ },
18
+ plugins: {
19
+ ...baseConfig.plugins,
20
+ },
21
+ settings: {
22
+ ...baseConfig.settings,
23
+ },
24
+ rules: {
25
+ ...baseConfig.rules,
26
+ },
27
+ },
28
+ // TypeScript-specific config
29
+ {
30
+ files: ['**/*.ts', '**/*.tsx'],
31
+ languageOptions: {
32
+ parser: tsParser,
33
+ parserOptions: {
34
+ project: ['./tsconfig.json'],
35
+ tsconfigRootDir: process.cwd(),
36
+ },
37
+ },
38
+ plugins: {
39
+ '@typescript-eslint': tsEslint,
40
+ },
41
+ settings: {
42
+ 'import/resolver': {
43
+ node: {
44
+ extensions: ['.mjs', '.js', '.json', '.node', '.ts', '.tsx'],
45
+ },
46
+ },
47
+ },
48
+ rules: {
49
+ 'import/extensions': [
50
+ 'error',
51
+ 'ignorePackages',
52
+ {
53
+ js: 'never',
54
+ jsx: 'never',
55
+ ts: 'never',
56
+ tsx: 'never',
57
+ },
58
+ ],
59
+ semi: [2, 'always'],
60
+ 'max-params': 'off',
61
+ 'no-throw-literal': 'off',
62
+ 'no-shadow': 'off',
63
+ 'no-empty-function': 'off',
64
+ 'no-plusplus': 'off',
65
+ 'no-unused-vars': 'off',
66
+ 'no-await-in-loop': 'error',
67
+ 'unicorn/no-array-callback-reference': 'off',
68
+ 'generator-star-spacing': 'off',
69
+ 'max-len': 'off',
70
+ 'no-console': 'warn',
71
+ 'indent': 'off',
72
+ 'quotes': 'off',
73
+ 'implicit-arrow-linebreak': 'off',
74
+ 'function-paren-newline': 'off',
75
+ 'no-redeclare': 'off',
76
+ 'brace-style': 'off',
77
+ 'no-undef': 'off',
78
+ 'no-tabs': 'off',
79
+ 'operator-linebreak': 'off',
80
+ 'no-confusing-arrow': 'off',
81
+ 'object-curly-newline': 'off',
82
+ '@typescript-eslint/only-throw-error': 'error',
83
+ '@typescript-eslint/no-unused-vars': 'error',
84
+ '@typescript-eslint/no-shadow': 'error',
85
+ '@typescript-eslint/return-await': 'error',
86
+ '@typescript-eslint/no-floating-promises': 'error',
87
+ '@typescript-eslint/no-explicit-any': 'error',
88
+ '@typescript-eslint/no-non-null-assertion': 'error',
89
+ '@typescript-eslint/no-var-requires': 'error',
90
+ '@typescript-eslint/explicit-member-accessibility': [
91
+ 'error',
92
+ {
93
+ accessibility: 'no-public',
94
+ },
95
+ ],
96
+ 'class-methods-use-this': 'off',
97
+ 'import/no-cycle': 'error',
98
+ 'promise/param-names': 'off',
99
+ 'no-use-before-define': ['warn', 'nofunc'],
100
+ 'no-restricted-syntax': [
101
+ 'error',
102
+ {
103
+ selector: ':matches(PropertyDefinition, MethodDefinition)[accessibility="private"]',
104
+ message: 'Use # prefix instead of `private` to indicate private class members.',
105
+ },
106
+ {
107
+ selector: 'ForInStatement',
108
+ message:
109
+ 'for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array.',
110
+ },
111
+ {
112
+ selector: 'LabeledStatement',
113
+ message:
114
+ 'Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.',
115
+ },
116
+ {
117
+ selector: 'WithStatement',
118
+ message:
119
+ '`with` is disallowed in strict mode because it makes code impossible to predict and optimize.',
120
+ },
121
+ ],
122
+ },
123
+ },
124
+ // Test files config
125
+ {
126
+ files: ['**/*.test.ts', '**/*.test.js'],
127
+ rules: {
128
+ 'max-classes-per-file': 'off',
129
+ '@typescript-eslint/no-non-null-assertion': 'off',
130
+ },
131
+ },
132
+ ];
133
+
134
+ module.exports = tsConfig;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * This file is GENERATED, please run `yarn update` after adding or renaming a rule
3
+ */
4
+ module.exports = {
5
+ configs: {
6
+ base: require('./configs/base.js'),
7
+ typescript: require('./configs/typescript.js'),
8
+ },
9
+ };
@@ -0,0 +1,78 @@
1
+ {
2
+ "name": "@gitlab/eslint-plugin/eslint9",
3
+ "version": "21.0.0",
4
+ "description": "GitLab package for our custom eslint rules - eslint 9 compatible",
5
+ "main": "lib/index.js",
6
+ "scripts": {
7
+ "createRule": "./scripts/createRule.js && yarn update",
8
+ "update": "./scripts/updateFiles.js && prettier --write lib/index.js",
9
+ "commit": "npx git-cz",
10
+ },
11
+ "repository": "https://gitlab.com/gitlab-org/frontend/eslint-plugin.git",
12
+ "keywords": [
13
+ "eslint",
14
+ "vue",
15
+ "i18n",
16
+ "internationalization",
17
+ "vuejs",
18
+ "linting",
19
+ "eslintplugin",
20
+ "eslint-plugin"
21
+ ],
22
+ "author": "GitLab Frontend Team <frontendteam@gitlab.com>",
23
+ "license": "MIT",
24
+ "bugs": {
25
+ "url": "https://gitlab.com/gitlab-org/frontend/eslint-plugin/issues"
26
+ },
27
+ "homepage": "https://gitlab.com/gitlab-org/frontend/eslint-plugin#readme",
28
+ "engines": {
29
+ "node": ">=20"
30
+ },
31
+ "dependencies": {
32
+ "@typescript-eslint/eslint-plugin": "^8.0.0",
33
+ "@typescript-eslint/parser": "^8.0.0",
34
+ "confusing-browser-globals": "^1.0.11",
35
+ "globals": "^15.0.0",
36
+ "eslint-config-prettier": "^9.1.0",
37
+ "eslint-plugin-import": "^2.29.1",
38
+ "eslint-plugin-jest": "^28.6.0",
39
+ "eslint-plugin-promise": "^7.0.0",
40
+ "eslint-plugin-unicorn": "^55.0.0",
41
+ "eslint-plugin-vue": "^9.27.0",
42
+ "vue-eslint-parser": "^9.4.3",
43
+ "lodash": "^4.17.21"
44
+ },
45
+ "peerDependencies": {
46
+ "eslint": "^9.29.0"
47
+ },
48
+ "devDependencies": {
49
+ "eslint": "^9.29.0",
50
+ "glob": "^7.2.0",
51
+ "jest": "^27.5.1",
52
+ "prettier": "^2.6.1",
53
+ "pretty-quick": "^3.1.3",
54
+ "yarn-deduplicate": "^6.0.2"
55
+ },
56
+ "release": {
57
+ "branches": [
58
+ "main"
59
+ ],
60
+ "verifyConditions": [
61
+ "@semantic-release/changelog",
62
+ "@semantic-release/npm",
63
+ "@semantic-release/git",
64
+ "@semantic-release/gitlab"
65
+ ],
66
+ "prepare": [
67
+ "@semantic-release/changelog",
68
+ "@semantic-release/npm",
69
+ "@semantic-release/git"
70
+ ],
71
+ "publish": [
72
+ "@semantic-release/npm",
73
+ "@semantic-release/gitlab"
74
+ ],
75
+ "success": false,
76
+ "fail": false
77
+ }
78
+ }