@infernodesign/eslint-config 2.19.0 → 2.20.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/cli.js +1 -1
- package/dist/index.d.ts +6 -0
- package/dist/index.js +163 -39
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -8,7 +8,7 @@ import { cac } from "cac";
|
|
|
8
8
|
import parse from "parse-gitignore";
|
|
9
9
|
import { execSync } from "node:child_process";
|
|
10
10
|
// package.json
|
|
11
|
-
var version = "2.
|
|
11
|
+
var version = "2.20.0";
|
|
12
12
|
// src/cli/constants.ts
|
|
13
13
|
const vscodeSettingsString = `
|
|
14
14
|
// Disable the default formatter, use eslint instead
|
package/dist/index.d.ts
CHANGED
|
@@ -5598,6 +5598,10 @@ interface RuleOptions {
|
|
|
5598
5598
|
* @see https://eslint.style/rules/jsx-self-closing-comp
|
|
5599
5599
|
*/
|
|
5600
5600
|
'style/jsx-self-closing-comp'?: Linter.RuleEntry<StyleJsxSelfClosingComp>;
|
|
5601
|
+
/**
|
|
5602
|
+
* Require a space before a self-closing JSX slash without splitting type arguments
|
|
5603
|
+
*/
|
|
5604
|
+
'style/jsx-self-closing-spacing'?: Linter.RuleEntry<StyleJsxSelfClosingSpacing>;
|
|
5601
5605
|
/**
|
|
5602
5606
|
* Enforce shorthand for boolean JSX attributes.
|
|
5603
5607
|
* @see https://eslint.style/rules/jsx-shorthand-boolean
|
|
@@ -18152,6 +18156,8 @@ type StyleJsxSelfClosingComp = [] | [{
|
|
|
18152
18156
|
component?: boolean;
|
|
18153
18157
|
html?: boolean;
|
|
18154
18158
|
}];
|
|
18159
|
+
// ----- style/jsx-self-closing-spacing -----
|
|
18160
|
+
type StyleJsxSelfClosingSpacing = [] | [("always" | "never" | "proportional-always" | "allow")];
|
|
18155
18161
|
// ----- style/jsx-tag-spacing -----
|
|
18156
18162
|
type StyleJsxTagSpacing = [] | [{
|
|
18157
18163
|
closingSlash?: ("always" | "never" | "allow");
|
package/dist/index.js
CHANGED
|
@@ -505,6 +505,122 @@ async function e18e(options = {}) {
|
|
|
505
505
|
}
|
|
506
506
|
}];
|
|
507
507
|
}
|
|
508
|
+
// src/rules/jsx-tag-spacing.ts
|
|
509
|
+
/**
|
|
510
|
+
* Read `beforeSelfClosing` from a `style/jsx-tag-spacing` entry.
|
|
511
|
+
*
|
|
512
|
+
* @param {Rules[string]} entry Configured `style/jsx-tag-spacing` entry.
|
|
513
|
+
* @returns {BeforeSelfClosing} The option, or `always` when the entry uses the preset default.
|
|
514
|
+
*/
|
|
515
|
+
function readBeforeSelfClosing(entry) {
|
|
516
|
+
if (!Array.isArray(entry)) return "always";
|
|
517
|
+
const options = entry[1];
|
|
518
|
+
if (!options || typeof options !== "object" || !("beforeSelfClosing" in options)) return "always";
|
|
519
|
+
const value = options.beforeSelfClosing;
|
|
520
|
+
if (value === "allow" || value === "always" || value === "never" || value === "proportional-always") return value;
|
|
521
|
+
return "always";
|
|
522
|
+
}
|
|
523
|
+
/**
|
|
524
|
+
* `@stylistic/jsx-tag-spacing` treats the `<` of `<FieldStep<V, O> />` as the closing
|
|
525
|
+
* bracket. Turn that check off and let {@link jsxSelfClosingSpacing} enforce the space
|
|
526
|
+
* before `/>` without rewriting the generic.
|
|
527
|
+
*
|
|
528
|
+
* @param {Rules} rules Stylistic rules, including user overrides.
|
|
529
|
+
* @param {boolean | undefined} jsx Whether JSX stylistic rules are enabled.
|
|
530
|
+
*/
|
|
531
|
+
function moveJsxSelfClosingCheck(rules, jsx) {
|
|
532
|
+
if (jsx === false) return;
|
|
533
|
+
const entry = rules["style/jsx-tag-spacing"];
|
|
534
|
+
if (entry == null || entry === "off" || entry === 0) return;
|
|
535
|
+
const beforeSelfClosing = readBeforeSelfClosing(entry);
|
|
536
|
+
const severity = Array.isArray(entry) ? entry[0] : entry;
|
|
537
|
+
rules["style/jsx-tag-spacing"] = [severity, {
|
|
538
|
+
...Array.isArray(entry) && entry[1] && typeof entry[1] === "object" ? entry[1] : {},
|
|
539
|
+
beforeSelfClosing: "allow"
|
|
540
|
+
}];
|
|
541
|
+
if (beforeSelfClosing !== "allow") rules["style/jsx-self-closing-spacing"] = [severity === 1 || severity === "warn" ? "warn" : "error", beforeSelfClosing];
|
|
542
|
+
}
|
|
543
|
+
/**
|
|
544
|
+
* Enforce the space before `/>`, skipping JSX type argument lists.
|
|
545
|
+
*
|
|
546
|
+
* `<FieldStep<V, O> />` keeps its generic tight. `<Foo/>` is still fixed to `<Foo />`.
|
|
547
|
+
*/
|
|
548
|
+
const jsxSelfClosingSpacing = {
|
|
549
|
+
create(context) {
|
|
550
|
+
const option = context.options[0] ?? "always";
|
|
551
|
+
const sourceCode = context.sourceCode;
|
|
552
|
+
/**
|
|
553
|
+
* Token that should sit immediately before `/>`.
|
|
554
|
+
*
|
|
555
|
+
* @param {JsxOpeningElement} node Self-closing JSX opening element.
|
|
556
|
+
* @returns {Rule.Node} The name, last attribute, or the `>` that closes a type argument list.
|
|
557
|
+
*/
|
|
558
|
+
function tokenBeforeClosingSlash(node) {
|
|
559
|
+
const attributes = node.attributes ?? [];
|
|
560
|
+
const attribute = attributes[attributes.length - 1];
|
|
561
|
+
if (attribute) return attribute;
|
|
562
|
+
const typeArguments = node.typeArguments ?? node.typeParameters;
|
|
563
|
+
return sourceCode.getLastToken(typeArguments ?? node.name) ?? node.name;
|
|
564
|
+
}
|
|
565
|
+
return { JSXOpeningElement(node) {
|
|
566
|
+
const opening = node;
|
|
567
|
+
if (!opening.selfClosing || option === "allow") return;
|
|
568
|
+
const left = tokenBeforeClosingSlash(opening);
|
|
569
|
+
const closingSlash = sourceCode.getTokenAfter(left);
|
|
570
|
+
if (!closingSlash?.loc || !left.loc) return;
|
|
571
|
+
const sameLine = left.loc.end.line === closingSlash.loc.start.line;
|
|
572
|
+
if (!(opening.loc.start.line === opening.loc.end.line) && option === "proportional-always") {
|
|
573
|
+
if (sameLine) context.report({
|
|
574
|
+
fix: (fixer) => fixer.insertTextBefore(closingSlash, "\n"),
|
|
575
|
+
loc: left.loc.end,
|
|
576
|
+
messageId: "needNewline",
|
|
577
|
+
node
|
|
578
|
+
});
|
|
579
|
+
return;
|
|
580
|
+
}
|
|
581
|
+
if (!sameLine) return;
|
|
582
|
+
const adjacent = !sourceCode.isSpaceBetween(left, closingSlash);
|
|
583
|
+
if ((option === "always" || option === "proportional-always") && adjacent) {
|
|
584
|
+
context.report({
|
|
585
|
+
fix: (fixer) => fixer.insertTextBefore(closingSlash, " "),
|
|
586
|
+
loc: closingSlash.loc.start,
|
|
587
|
+
messageId: "needSpace",
|
|
588
|
+
node
|
|
589
|
+
});
|
|
590
|
+
return;
|
|
591
|
+
}
|
|
592
|
+
if (option === "never" && !adjacent) {
|
|
593
|
+
const previousToken = sourceCode.getTokenBefore(closingSlash);
|
|
594
|
+
if (!previousToken) return;
|
|
595
|
+
context.report({
|
|
596
|
+
fix: (fixer) => fixer.removeRange([previousToken.range[1], closingSlash.range[0]]),
|
|
597
|
+
loc: closingSlash.loc.start,
|
|
598
|
+
messageId: "noSpace",
|
|
599
|
+
node
|
|
600
|
+
});
|
|
601
|
+
}
|
|
602
|
+
} };
|
|
603
|
+
},
|
|
604
|
+
meta: {
|
|
605
|
+
docs: { description: "Require a space before a self-closing JSX slash without splitting type arguments" },
|
|
606
|
+
fixable: "whitespace",
|
|
607
|
+
messages: {
|
|
608
|
+
needNewline: "A newline is required before closing bracket",
|
|
609
|
+
needSpace: "A space is required before closing bracket",
|
|
610
|
+
noSpace: "A space is forbidden before closing bracket"
|
|
611
|
+
},
|
|
612
|
+
schema: [{
|
|
613
|
+
enum: [
|
|
614
|
+
"always",
|
|
615
|
+
"never",
|
|
616
|
+
"proportional-always",
|
|
617
|
+
"allow"
|
|
618
|
+
],
|
|
619
|
+
type: "string"
|
|
620
|
+
}],
|
|
621
|
+
type: "layout"
|
|
622
|
+
}
|
|
623
|
+
};
|
|
508
624
|
// src/configs/stylistic.ts
|
|
509
625
|
const StylisticConfigDefaults = {
|
|
510
626
|
arrowParens: true,
|
|
@@ -524,50 +640,58 @@ async function stylistic(options = {}) {
|
|
|
524
640
|
...options
|
|
525
641
|
};
|
|
526
642
|
const pluginStylistic = await interopDefault(import("@stylistic/eslint-plugin"));
|
|
527
|
-
const
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
643
|
+
const stylePlugin = {
|
|
644
|
+
...pluginStylistic,
|
|
645
|
+
rules: {
|
|
646
|
+
...pluginStylistic.rules,
|
|
647
|
+
"jsx-self-closing-spacing": jsxSelfClosingSpacing
|
|
648
|
+
}
|
|
649
|
+
};
|
|
650
|
+
const rules = {
|
|
651
|
+
...pluginStylistic.configs.customize({
|
|
652
|
+
arrowParens,
|
|
653
|
+
blockSpacing,
|
|
654
|
+
braceStyle,
|
|
655
|
+
commaDangle,
|
|
656
|
+
experimental,
|
|
657
|
+
indent,
|
|
658
|
+
jsx,
|
|
659
|
+
pluginName: "style",
|
|
660
|
+
quoteProps,
|
|
661
|
+
quotes,
|
|
662
|
+
semi
|
|
663
|
+
}).rules,
|
|
664
|
+
"antfu/consistent-chaining": "error",
|
|
665
|
+
...lessOpinionated ? { "curly": "off" } : { "antfu/curly": "error" },
|
|
666
|
+
"style/max-len": "off",
|
|
667
|
+
"style/max-statements-per-line": "off",
|
|
668
|
+
"style/multiline-ternary": "off",
|
|
669
|
+
"style/quotes": [
|
|
670
|
+
"error",
|
|
671
|
+
"single",
|
|
672
|
+
{
|
|
673
|
+
avoidEscape: true,
|
|
674
|
+
allowTemplateLiterals: "avoidEscape"
|
|
675
|
+
}
|
|
676
|
+
],
|
|
677
|
+
"style/generator-star-spacing": ["error", {
|
|
678
|
+
after: true,
|
|
679
|
+
before: false
|
|
680
|
+
}],
|
|
681
|
+
"style/yield-star-spacing": ["error", {
|
|
682
|
+
after: true,
|
|
683
|
+
before: false
|
|
684
|
+
}],
|
|
685
|
+
...overrides
|
|
686
|
+
};
|
|
687
|
+
moveJsxSelfClosingCheck(rules, jsx);
|
|
540
688
|
return [{
|
|
541
689
|
name: "config/stylistic/rules",
|
|
542
690
|
plugins: {
|
|
543
691
|
antfu: pluginAntfu,
|
|
544
|
-
style:
|
|
692
|
+
style: stylePlugin
|
|
545
693
|
},
|
|
546
|
-
rules
|
|
547
|
-
...config.rules,
|
|
548
|
-
"antfu/consistent-chaining": "error",
|
|
549
|
-
...lessOpinionated ? { "curly": "off" } : { "antfu/curly": "error" },
|
|
550
|
-
"style/max-len": "off",
|
|
551
|
-
"style/max-statements-per-line": "off",
|
|
552
|
-
"style/multiline-ternary": "off",
|
|
553
|
-
"style/quotes": [
|
|
554
|
-
"error",
|
|
555
|
-
"single",
|
|
556
|
-
{
|
|
557
|
-
avoidEscape: true,
|
|
558
|
-
allowTemplateLiterals: "avoidEscape"
|
|
559
|
-
}
|
|
560
|
-
],
|
|
561
|
-
"style/generator-star-spacing": ["error", {
|
|
562
|
-
after: true,
|
|
563
|
-
before: false
|
|
564
|
-
}],
|
|
565
|
-
"style/yield-star-spacing": ["error", {
|
|
566
|
-
after: true,
|
|
567
|
-
before: false
|
|
568
|
-
}],
|
|
569
|
-
...overrides
|
|
570
|
-
}
|
|
694
|
+
rules
|
|
571
695
|
}];
|
|
572
696
|
}
|
|
573
697
|
// src/configs/formatters.ts
|
package/package.json
CHANGED