@nitra/eslint-config 2.0.13 → 2.0.15

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.
Files changed (2) hide show
  1. package/index.js +150 -78
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -7,91 +7,163 @@ import securityPlugin from 'eslint-plugin-security'
7
7
  import pluginVue from 'eslint-plugin-vue'
8
8
  import globals from 'globals'
9
9
 
10
- export default {
11
- all: [
12
- {
13
- // До дефолтних "**/node_modules/", ".git/" додаємо
14
- ignores: ['.yarn/**', '**/dist/**']
10
+ const all = [
11
+ {
12
+ // До дефолтних "**/node_modules/", ".git/" додаємо
13
+ ignores: ['.yarn/**', '**/dist/**']
14
+ },
15
+ // Загальні правила для всіх js файлів проекту
16
+ {
17
+ files: ['**/*.js'],
18
+ languageOptions: {
19
+ ecmaVersion: 13,
20
+ sourceType: 'module'
15
21
  },
16
-
17
- {
18
- files: ['**/vite.config.js'],
19
- languageOptions: {
20
- globals: {
21
- process: 'readonly',
22
- __dirname: 'readonly'
23
- }
24
- }
22
+ plugins: {
23
+ prettier: configPrettier,
24
+ standard: configStandard
25
25
  },
26
- {
27
- files: ['**/*.js'],
28
- languageOptions: {
29
- ecmaVersion: 13,
30
- sourceType: 'module'
31
- },
32
- plugins: {
33
- prettier: configPrettier,
34
- standard: configStandard
35
- },
36
- rules: {
37
- ...js.configs.recommended.rules,
38
- 'no-unused-vars': ['error', { argsIgnorePattern: '^_', varsIgnorePattern: '^_' }]
39
- }
26
+ rules: {
27
+ ...js.configs.recommended.rules,
28
+ 'no-unused-vars': ['error', { argsIgnorePattern: '^_', varsIgnorePattern: '^_' }]
29
+ }
30
+ }
31
+ ]
32
+ // Тільки для node js проектів
33
+ const node = [
34
+ nodePlugin.configs['flat/recommended-module'],
35
+ securityPlugin.configs.recommended,
36
+ { plugins: { '@microsoft/eslint-plugin-sdl': sdlPlugin } },
37
+ {
38
+ rules: {
39
+ 'security/detect-non-literal-fs-filename': 'off',
40
+ 'security/detect-object-injection': 'off'
40
41
  }
41
- ],
42
- node: [
43
- nodePlugin.configs['flat/recommended-module'],
44
- securityPlugin.configs.recommended,
45
- { plugins: { '@microsoft/eslint-plugin-sdl': sdlPlugin } },
46
- {
47
- rules: {
48
- 'security/detect-non-literal-fs-filename': 'off',
49
- 'security/detect-object-injection': 'off'
42
+ }
43
+ ]
44
+
45
+ // Тільки для Vue проектів
46
+ // files: ['**/vite.config.js']
47
+ const vueVite = [
48
+ {
49
+ languageOptions: {
50
+ globals: {
51
+ process: 'readonly',
52
+ __dirname: 'readonly'
50
53
  }
51
54
  }
52
- ],
53
- vue: [
54
- ...pluginVue.configs['flat/recommended'],
55
- {
56
- languageOptions: {
57
- globals: {
58
- ...globals.browser,
59
- createLogger: 'readonly',
60
- gql: 'readonly',
61
- $ref: 'readonly',
62
- ref: 'readonly',
63
- useQuery: 'readonly',
64
- watch: 'readonly'
65
- }
55
+ }
56
+ ]
57
+
58
+ // Для усіх файлів Vue проектів
59
+ // files: ['**/*.js', '**/*.vue']
60
+ const vueAllVite = [
61
+ {
62
+ languageOptions: {
63
+ globals: {
64
+ ...globals.browser,
65
+ createLogger: 'readonly',
66
+ gql: 'readonly',
67
+ $ref: 'readonly',
68
+ ref: 'readonly',
69
+ useQuery: 'readonly',
70
+ watch: 'readonly',
71
+ computed: 'readonly'
66
72
  }
67
- },
68
- {
69
- rules: {
70
- 'vue/html-indent': 'off',
71
- 'vue/max-attributes-per-line': 'off',
72
- 'vue/html-closing-bracket-newline': 'off',
73
- 'vue/singleline-html-element-content-newline': 'off',
74
- 'vue/multi-word-component-names': 'off',
75
- 'vue/html-self-closing': [
76
- 'error',
77
- {
78
- html: {
79
- void: 'always' // під преттієр https://github.com/prettier/prettier/issues/5641
80
- }
73
+ }
74
+ }
75
+ ]
76
+
77
+ // Для Vue файлів Vue проектів
78
+ // files: ['**/*.vue']
79
+ const vue = [
80
+ ...pluginVue.configs['flat/recommended'],
81
+ {
82
+ rules: {
83
+ 'vue/no-v-html': 'off',
84
+ 'vue/html-indent': 'off',
85
+ 'vue/max-attributes-per-line': 'off',
86
+ 'vue/html-closing-bracket-newline': 'off',
87
+ 'vue/singleline-html-element-content-newline': 'off',
88
+ 'vue/multi-word-component-names': 'off',
89
+ 'vue/html-self-closing': [
90
+ 'error',
91
+ {
92
+ html: {
93
+ void: 'always' // під преттієр https://github.com/prettier/prettier/issues/5641
81
94
  }
82
- ]
83
- }
95
+ }
96
+ ],
97
+ // Нітра порядок сортування
98
+ 'vue/attributes-order': [
99
+ 'error',
100
+ {
101
+ order: [
102
+ 'DEFINITION',
103
+ 'LIST_RENDERING',
104
+ 'CONDITIONALS',
105
+ 'RENDER_MODIFIERS',
106
+ 'GLOBAL',
107
+ ['UNIQUE', 'SLOT'],
108
+ 'TWO_WAY_BINDING',
109
+ 'OTHER_DIRECTIVES',
110
+ 'EVENTS',
111
+ 'OTHER_ATTR',
112
+ 'CONTENT'
113
+ ],
114
+ alphabetical: false
115
+ }
116
+ ]
84
117
  }
85
- ]
86
- }
118
+ }
119
+ ]
87
120
 
88
- // const nodeConfig = sharableConfig.configs.node.map(configObject => ({
89
- // files: ['run/**/*.js'],
90
- // ...configObject
91
- // }))
92
- // const vueConfig = sharableConfig.configs.vue.map(configObject => ({
93
- // files: ['site/**/*.vue'],
94
- // ...configObject
95
- // }))
121
+ /**
122
+ * Eslint правила
123
+ *
124
+ * @param {{node?: Array, vue?: Array}} params список директорій до яких примінити Eslint правили
125
+ */
126
+ export function getConfig(params = { node: [], vue: [] }) {
127
+ const result = all
96
128
 
97
- // export default [...sharableConfig.configs.all, ...nodeConfig, ...vueConfig]
129
+ // якщо присутні nodejs проекти в monorepo
130
+ if (params.node) {
131
+ const files = params.node.map(name => `${name}/**/*.js`)
132
+ const nodeConfig = node.map(configObject => ({
133
+ files,
134
+ ...configObject
135
+ }))
136
+ result.push(...nodeConfig)
137
+ }
138
+
139
+ // якщо присутні nodejs проекти в monorepo
140
+ if (params.vue) {
141
+ // по певним файлам правили
142
+ const filesVite = params.vue.map(name => `${name}/**/vite.config.js`)
143
+ const vueViteConfig = vueVite.map(configObject => ({
144
+ files: filesVite,
145
+ ...configObject
146
+ }))
147
+ // @ts-ignore
148
+ result.push(...vueViteConfig)
149
+
150
+ // Для Vue файлів правила
151
+ const files = params.vue.map(name => `${name}/**/*.vue`)
152
+ const vueConfig = [...vueAllVite, ...vue].map(configObject => ({
153
+ files,
154
+ ...configObject
155
+ }))
156
+ result.push(...vueConfig)
157
+
158
+ // Для js файлів всередині Vue проектів правила
159
+ const filesJS = params.vue.map(name => `${name}/**/*.js`)
160
+ const vueJSConfig = vueAllVite.map(configObject => ({
161
+ files: filesJS,
162
+ ...configObject
163
+ }))
164
+ // @ts-ignore
165
+ result.push(...vueJSConfig)
166
+ }
167
+
168
+ return result
169
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nitra/eslint-config",
3
- "version": "2.0.13",
3
+ "version": "2.0.15",
4
4
  "description": "A Eslint shareable config for projects using 'Vue' and 'Node'",
5
5
  "type": "module",
6
6
  "exports": "./index.js",