@so1ve/eslint-plugin 3.3.0 → 3.3.2
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 +7 -0
- package/dist/index.js +80 -17
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,12 @@ import * as _typescript_eslint_utils_ts_eslint1 from "@typescript-eslint/utils/t
|
|
|
3
3
|
//#region src/rules/function-style.d.ts
|
|
4
4
|
type MessageIds = "arrow" | "declaration";
|
|
5
5
|
//#endregion
|
|
6
|
+
//#region src/rules/vue-root-element-sort-attributes.d.ts
|
|
7
|
+
type Options = [{
|
|
8
|
+
script?: string[];
|
|
9
|
+
[otherElement: string]: string[] | undefined;
|
|
10
|
+
}];
|
|
11
|
+
//#endregion
|
|
6
12
|
//#region src/index.d.ts
|
|
7
13
|
declare const _default: {
|
|
8
14
|
rules: {
|
|
@@ -14,6 +20,7 @@ declare const _default: {
|
|
|
14
20
|
"no-import-promises-as": _typescript_eslint_utils_ts_eslint1.RuleModule<"noImportPromisesAs", [], unknown, _typescript_eslint_utils_ts_eslint1.RuleListener>;
|
|
15
21
|
"pad-after-last-import": _typescript_eslint_utils_ts_eslint1.RuleModule<"padAfterLastImport", [], unknown, _typescript_eslint_utils_ts_eslint1.RuleListener>;
|
|
16
22
|
"require-async-with-await": _typescript_eslint_utils_ts_eslint1.RuleModule<"requireAsyncWithAwait", [], unknown, _typescript_eslint_utils_ts_eslint1.RuleListener>;
|
|
23
|
+
"vue-root-element-sort-attributes": _typescript_eslint_utils_ts_eslint1.RuleModule<"wrongOrder", Options, unknown, _typescript_eslint_utils_ts_eslint1.RuleListener>;
|
|
17
24
|
};
|
|
18
25
|
};
|
|
19
26
|
//#endregion
|
package/dist/index.js
CHANGED
|
@@ -16,9 +16,9 @@ function getPreviousNode(node) {
|
|
|
16
16
|
|
|
17
17
|
//#endregion
|
|
18
18
|
//#region src/rules/function-style.ts
|
|
19
|
-
const RULE_NAME$
|
|
19
|
+
const RULE_NAME$8 = "function-style";
|
|
20
20
|
var function_style_default = createEslintRule({
|
|
21
|
-
name: RULE_NAME$
|
|
21
|
+
name: RULE_NAME$8,
|
|
22
22
|
meta: {
|
|
23
23
|
type: "problem",
|
|
24
24
|
docs: { description: "Enforce function style." },
|
|
@@ -129,9 +129,9 @@ var function_style_default = createEslintRule({
|
|
|
129
129
|
|
|
130
130
|
//#endregion
|
|
131
131
|
//#region src/rules/import-dedupe.ts
|
|
132
|
-
const RULE_NAME$
|
|
132
|
+
const RULE_NAME$7 = "import-dedupe";
|
|
133
133
|
var import_dedupe_default = createEslintRule({
|
|
134
|
-
name: RULE_NAME$
|
|
134
|
+
name: RULE_NAME$7,
|
|
135
135
|
meta: {
|
|
136
136
|
type: "problem",
|
|
137
137
|
docs: { description: "Fix duplication in imports." },
|
|
@@ -167,7 +167,7 @@ var import_dedupe_default = createEslintRule({
|
|
|
167
167
|
|
|
168
168
|
//#endregion
|
|
169
169
|
//#region src/rules/no-import-promises-as.ts
|
|
170
|
-
const RULE_NAME$
|
|
170
|
+
const RULE_NAME$6 = "no-import-promises-as";
|
|
171
171
|
const _POSSIBLE_IMPORT_SOURCES = [
|
|
172
172
|
"dns",
|
|
173
173
|
"fs",
|
|
@@ -176,7 +176,7 @@ const _POSSIBLE_IMPORT_SOURCES = [
|
|
|
176
176
|
];
|
|
177
177
|
const POSSIBLE_IMPORT_SOURCES = [..._POSSIBLE_IMPORT_SOURCES, ..._POSSIBLE_IMPORT_SOURCES.map((s) => `node:${s}`)];
|
|
178
178
|
var no_import_promises_as_default = createEslintRule({
|
|
179
|
-
name: RULE_NAME$
|
|
179
|
+
name: RULE_NAME$6,
|
|
180
180
|
meta: {
|
|
181
181
|
type: "problem",
|
|
182
182
|
docs: { description: "Disallow import promises as." },
|
|
@@ -210,9 +210,9 @@ var no_import_promises_as_default = createEslintRule({
|
|
|
210
210
|
|
|
211
211
|
//#endregion
|
|
212
212
|
//#region src/rules/no-inline-type-import.ts
|
|
213
|
-
const RULE_NAME$
|
|
213
|
+
const RULE_NAME$5 = "no-inline-type-import";
|
|
214
214
|
var no_inline_type_import_default = createEslintRule({
|
|
215
|
-
name: RULE_NAME$
|
|
215
|
+
name: RULE_NAME$5,
|
|
216
216
|
meta: {
|
|
217
217
|
type: "layout",
|
|
218
218
|
docs: { description: "Disallow inline type import." },
|
|
@@ -254,7 +254,7 @@ var no_inline_type_import_default = createEslintRule({
|
|
|
254
254
|
|
|
255
255
|
//#endregion
|
|
256
256
|
//#region src/rules/no-negated-comparison.ts
|
|
257
|
-
const RULE_NAME$
|
|
257
|
+
const RULE_NAME$4 = "no-negated-comparison";
|
|
258
258
|
const negatedToPositive = {
|
|
259
259
|
"==": "!=",
|
|
260
260
|
"===": "!==",
|
|
@@ -267,7 +267,7 @@ const negatedToPositive = {
|
|
|
267
267
|
};
|
|
268
268
|
const negatives = Object.keys(negatedToPositive);
|
|
269
269
|
var no_negated_comparison_default = createEslintRule({
|
|
270
|
-
name: RULE_NAME$
|
|
270
|
+
name: RULE_NAME$4,
|
|
271
271
|
meta: {
|
|
272
272
|
type: "problem",
|
|
273
273
|
docs: { description: "Disallow negated comparison." },
|
|
@@ -294,9 +294,9 @@ var no_negated_comparison_default = createEslintRule({
|
|
|
294
294
|
|
|
295
295
|
//#endregion
|
|
296
296
|
//#region src/rules/no-useless-template-string.ts
|
|
297
|
-
const RULE_NAME$
|
|
297
|
+
const RULE_NAME$3 = "no-useless-template-string";
|
|
298
298
|
var no_useless_template_string_default = createEslintRule({
|
|
299
|
-
name: RULE_NAME$
|
|
299
|
+
name: RULE_NAME$3,
|
|
300
300
|
meta: {
|
|
301
301
|
type: "problem",
|
|
302
302
|
docs: { description: "No useless template string." },
|
|
@@ -320,9 +320,9 @@ var no_useless_template_string_default = createEslintRule({
|
|
|
320
320
|
|
|
321
321
|
//#endregion
|
|
322
322
|
//#region src/rules/pad-after-last-import.ts
|
|
323
|
-
const RULE_NAME$
|
|
323
|
+
const RULE_NAME$2 = "pad-after-last-import";
|
|
324
324
|
var pad_after_last_import_default = createEslintRule({
|
|
325
|
-
name: RULE_NAME$
|
|
325
|
+
name: RULE_NAME$2,
|
|
326
326
|
meta: {
|
|
327
327
|
type: "problem",
|
|
328
328
|
docs: { description: "Pad after the last import." },
|
|
@@ -357,9 +357,9 @@ var pad_after_last_import_default = createEslintRule({
|
|
|
357
357
|
|
|
358
358
|
//#endregion
|
|
359
359
|
//#region src/rules/require-async-with-await.ts
|
|
360
|
-
const RULE_NAME = "require-async-with-await";
|
|
360
|
+
const RULE_NAME$1 = "require-async-with-await";
|
|
361
361
|
var require_async_with_await_default = createEslintRule({
|
|
362
|
-
name: RULE_NAME,
|
|
362
|
+
name: RULE_NAME$1,
|
|
363
363
|
meta: {
|
|
364
364
|
type: "problem",
|
|
365
365
|
docs: { description: "Require using async keyword with await." },
|
|
@@ -401,6 +401,68 @@ var require_async_with_await_default = createEslintRule({
|
|
|
401
401
|
}
|
|
402
402
|
});
|
|
403
403
|
|
|
404
|
+
//#endregion
|
|
405
|
+
//#region src/rules/vue-root-element-sort-attributes.ts
|
|
406
|
+
const RULE_NAME = "vue-root-element-sort-attributes";
|
|
407
|
+
const defaultOptions = { script: ["setup", "lang"] };
|
|
408
|
+
var vue_root_element_sort_attributes_default = createEslintRule({
|
|
409
|
+
name: RULE_NAME,
|
|
410
|
+
meta: {
|
|
411
|
+
type: "layout",
|
|
412
|
+
docs: { description: "Sort attributes of root <script>, <template>, and <style> elements in Vue files." },
|
|
413
|
+
fixable: "code",
|
|
414
|
+
schema: [{
|
|
415
|
+
type: "object",
|
|
416
|
+
properties: { script: {
|
|
417
|
+
type: "array",
|
|
418
|
+
items: { type: "string" }
|
|
419
|
+
} },
|
|
420
|
+
additionalProperties: true
|
|
421
|
+
}],
|
|
422
|
+
messages: { wrongOrder: "Attributes of root element should be sorted in a specific order." }
|
|
423
|
+
},
|
|
424
|
+
defaultOptions: [defaultOptions],
|
|
425
|
+
create(context, [options]) {
|
|
426
|
+
const order = {
|
|
427
|
+
...options,
|
|
428
|
+
script: options.script ?? defaultOptions.script
|
|
429
|
+
};
|
|
430
|
+
const sourceCode = context.sourceCode;
|
|
431
|
+
const documentFragment = sourceCode.parserServices.getDocumentFragment?.();
|
|
432
|
+
function getTopLevelHTMLElements() {
|
|
433
|
+
if (documentFragment) return documentFragment.children.filter((n) => n.type === "VElement");
|
|
434
|
+
return [];
|
|
435
|
+
}
|
|
436
|
+
return { Program: (_node) => {
|
|
437
|
+
const topLevelElements = getTopLevelHTMLElements();
|
|
438
|
+
for (const element of topLevelElements) {
|
|
439
|
+
if (!(element.name in order)) continue;
|
|
440
|
+
const expectedOrder = order[element.name];
|
|
441
|
+
const attributesToCheck = [];
|
|
442
|
+
let reprintAttributes = false;
|
|
443
|
+
for (const attribute of element.startTag.attributes) {
|
|
444
|
+
if (attribute.key.type !== "VIdentifier" || attribute.directive) continue;
|
|
445
|
+
if (expectedOrder.includes(attribute.key.name)) attributesToCheck.push(attribute);
|
|
446
|
+
}
|
|
447
|
+
for (const attribute of attributesToCheck) {
|
|
448
|
+
const index = expectedOrder.indexOf(attribute.key.name);
|
|
449
|
+
if (index !== -1 && index !== attributesToCheck.indexOf(attribute)) reprintAttributes = true;
|
|
450
|
+
}
|
|
451
|
+
if (reprintAttributes) context.report({
|
|
452
|
+
node: element.startTag,
|
|
453
|
+
messageId: "wrongOrder",
|
|
454
|
+
*fix(fixer) {
|
|
455
|
+
const sortedAttributes = attributesToCheck.sort((a, b) => expectedOrder.indexOf(a.key.name) - expectedOrder.indexOf(b.key.name));
|
|
456
|
+
const attributeText = ` ${sortedAttributes.map((attr) => sourceCode.getText(attr)).join(" ")}`;
|
|
457
|
+
for (const attribute of sortedAttributes) yield fixer.remove(attribute);
|
|
458
|
+
yield fixer.replaceTextRange([element.startTag.range[1] - 1, element.startTag.range[1] - 1], attributeText);
|
|
459
|
+
}
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
} };
|
|
463
|
+
}
|
|
464
|
+
});
|
|
465
|
+
|
|
404
466
|
//#endregion
|
|
405
467
|
//#region src/index.ts
|
|
406
468
|
var src_default = { rules: {
|
|
@@ -411,7 +473,8 @@ var src_default = { rules: {
|
|
|
411
473
|
"no-useless-template-string": no_useless_template_string_default,
|
|
412
474
|
"no-import-promises-as": no_import_promises_as_default,
|
|
413
475
|
"pad-after-last-import": pad_after_last_import_default,
|
|
414
|
-
"require-async-with-await": require_async_with_await_default
|
|
476
|
+
"require-async-with-await": require_async_with_await_default,
|
|
477
|
+
"vue-root-element-sort-attributes": vue_root_element_sort_attributes_default
|
|
415
478
|
} };
|
|
416
479
|
|
|
417
480
|
//#endregion
|