@zjutjh/eslint-config 0.1.0 → 0.2.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/dist/index.d.ts +8 -2
- package/dist/index.js +38 -12
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import { Linter } from 'eslint';
|
|
2
2
|
|
|
3
|
-
type
|
|
3
|
+
type OverridesConfigs = {
|
|
4
|
+
vue?: Linter.RulesRecord;
|
|
5
|
+
ts?: Linter.RulesRecord;
|
|
6
|
+
stylistic?: Linter.RulesRecord;
|
|
7
|
+
};
|
|
8
|
+
type OptionsConfig = {
|
|
4
9
|
vue?: boolean;
|
|
5
10
|
ts?: boolean;
|
|
6
11
|
taro?: boolean;
|
|
12
|
+
overrides?: OverridesConfigs;
|
|
7
13
|
};
|
|
8
14
|
|
|
9
|
-
declare function zjutjh(options?:
|
|
15
|
+
declare function zjutjh(options?: OptionsConfig): Promise<Linter.Config<Linter.RulesRecord>[]>;
|
|
10
16
|
|
|
11
17
|
export { zjutjh as default };
|
package/dist/index.js
CHANGED
|
@@ -36,7 +36,6 @@ function javascript() {
|
|
|
36
36
|
"no-warning-comments": "warn",
|
|
37
37
|
"no-console": ["warn", { allow: ["warn", "error"] }],
|
|
38
38
|
"no-var": "error",
|
|
39
|
-
// TODO:
|
|
40
39
|
"no-undef": "off",
|
|
41
40
|
"prefer-const": "warn"
|
|
42
41
|
}
|
|
@@ -46,7 +45,7 @@ function javascript() {
|
|
|
46
45
|
|
|
47
46
|
// src/configs/stylistic.ts
|
|
48
47
|
import pluginStylistic from "@stylistic/eslint-plugin";
|
|
49
|
-
function stylistic() {
|
|
48
|
+
function stylistic(options) {
|
|
50
49
|
return [
|
|
51
50
|
{
|
|
52
51
|
name: "zjutjh/stylistic/rules",
|
|
@@ -80,7 +79,8 @@ function stylistic() {
|
|
|
80
79
|
}],
|
|
81
80
|
"@stylistic/space-in-parens": "error",
|
|
82
81
|
"@stylistic/space-infix-ops": "error",
|
|
83
|
-
"@stylistic/spaced-comment": "error"
|
|
82
|
+
"@stylistic/spaced-comment": "error",
|
|
83
|
+
...options.overrides
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
];
|
|
@@ -95,9 +95,25 @@ async function interopDefault(m) {
|
|
|
95
95
|
const resolved = await m;
|
|
96
96
|
return resolved.default || resolved;
|
|
97
97
|
}
|
|
98
|
+
async function ensurePackages(packages) {
|
|
99
|
+
const nonExistingPackages = packages.filter((i) => i && !isPackageExists(i));
|
|
100
|
+
if (nonExistingPackages.length !== 0) {
|
|
101
|
+
const message = `${nonExistingPackages.length === 1 ? "Package is" : "Packages are"} required for this config: ${nonExistingPackages.join(", ")}.`;
|
|
102
|
+
throw new Error(message);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
function getOverrides(options, key) {
|
|
106
|
+
return {
|
|
107
|
+
...options.overrides?.[key]
|
|
108
|
+
};
|
|
109
|
+
}
|
|
98
110
|
|
|
99
111
|
// src/configs/vue.ts
|
|
100
112
|
async function vue(options) {
|
|
113
|
+
await ensurePackages([
|
|
114
|
+
"eslint-plugin-vue",
|
|
115
|
+
"vue-eslint-parser"
|
|
116
|
+
]);
|
|
101
117
|
const [
|
|
102
118
|
pluginVue,
|
|
103
119
|
parserVue
|
|
@@ -134,14 +150,15 @@ async function vue(options) {
|
|
|
134
150
|
"vue/multi-word-component-names": "warn",
|
|
135
151
|
"vue/component-name-in-template-casing": ["error", "kebab-case", { "registeredComponentsOnly": true }],
|
|
136
152
|
"vue/max-attributes-per-line": ["error", { "singleline": { "max": 3 } }],
|
|
137
|
-
"vue/prefer-true-attribute-shorthand": ["warn", options?.taro ? "never" : "always"]
|
|
153
|
+
"vue/prefer-true-attribute-shorthand": ["warn", options?.taro ? "never" : "always"],
|
|
154
|
+
...options?.overrides
|
|
138
155
|
}
|
|
139
156
|
}
|
|
140
157
|
];
|
|
141
158
|
}
|
|
142
159
|
|
|
143
160
|
// src/configs/typescript.ts
|
|
144
|
-
async function typescript() {
|
|
161
|
+
async function typescript(options) {
|
|
145
162
|
const [
|
|
146
163
|
pluginTs,
|
|
147
164
|
parserTs
|
|
@@ -183,28 +200,37 @@ async function typescript() {
|
|
|
183
200
|
allowShortCircuit: true,
|
|
184
201
|
allowTaggedTemplates: true,
|
|
185
202
|
allowTernary: true
|
|
186
|
-
}]
|
|
203
|
+
}],
|
|
204
|
+
...options.overrides
|
|
187
205
|
}
|
|
188
206
|
}
|
|
189
207
|
];
|
|
190
208
|
}
|
|
191
209
|
|
|
192
210
|
// src/factory.ts
|
|
193
|
-
async function zjutjh(options) {
|
|
211
|
+
async function zjutjh(options = {}) {
|
|
194
212
|
const {
|
|
195
213
|
vue: enableVue = isPackageExists2("vue"),
|
|
196
214
|
ts: enableTs = isPackageExists2("typescript"),
|
|
197
|
-
taro:
|
|
198
|
-
} = options
|
|
215
|
+
taro: enableTaro = isPackageExists2("@tarojs/taro")
|
|
216
|
+
} = options;
|
|
199
217
|
const configs = [];
|
|
200
218
|
configs.push(javascript());
|
|
201
|
-
configs.push(
|
|
219
|
+
configs.push(
|
|
220
|
+
stylistic({ overrides: getOverrides(options, "stylistic") })
|
|
221
|
+
);
|
|
222
|
+
if (enableTs) configs.push(
|
|
223
|
+
await typescript({ overrides: getOverrides(options, "ts") })
|
|
224
|
+
);
|
|
202
225
|
if (enableVue) {
|
|
203
226
|
configs.push(
|
|
204
|
-
await vue({
|
|
227
|
+
await vue({
|
|
228
|
+
ts: enableTs,
|
|
229
|
+
taro: enableTaro,
|
|
230
|
+
overrides: getOverrides(options, "vue")
|
|
231
|
+
})
|
|
205
232
|
);
|
|
206
233
|
}
|
|
207
|
-
if (enableTs) configs.push(await typescript());
|
|
208
234
|
return configs.flat(1);
|
|
209
235
|
}
|
|
210
236
|
|