Skip to content

Commit 8a24ef2

Browse files
Add eslint-plugin-import (#711)
* Add `eslint-plugin-import` * Use `import/order`
1 parent 60d13b8 commit 8a24ef2

File tree

123 files changed

+2029
-748
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

123 files changed

+2029
-748
lines changed

.eslintrc.js

+11
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ module.exports = {
1414
"plugin:@ota-meshi/+yaml",
1515
// "plugin:@ota-meshi/+md",
1616
"plugin:@ota-meshi/+prettier",
17+
"plugin:import/recommended",
1718
"plugin:regexp/recommended",
1819
],
1920
rules: {
@@ -73,6 +74,8 @@ module.exports = {
7374
},
7475
],
7576

77+
"import/order": ["warn", { alphabetize: { order: "asc" } }],
78+
7679
// regexp next recommended
7780
"regexp/no-contradiction-with-assertion": "error",
7881
"regexp/no-empty-character-class": "error",
@@ -118,6 +121,12 @@ module.exports = {
118121
"no-implicit-globals": "off",
119122
"@typescript-eslint/naming-convention": "off",
120123
},
124+
settings: {
125+
"import/resolver": {
126+
typescript: true,
127+
node: true,
128+
},
129+
},
121130
},
122131
{
123132
files: ["lib/rules/**"],
@@ -148,6 +157,8 @@ module.exports = {
148157
rules: {
149158
"vue/multi-word-component-names": "off",
150159
"@typescript-eslint/no-explicit-any": "off",
160+
"import/named": "off",
161+
"import/no-unresolved": "off",
151162
},
152163
},
153164
{

docs/.vitepress/build-system/build.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
* Pre-build cjs packages that cannot be bundled well.
33
*/
44

5-
import esbuild from "esbuild"
6-
import path from "path"
75
import fs from "fs"
6+
import path from "path"
87
import { fileURLToPath } from "url"
8+
import esbuild from "esbuild"
99

1010
const dirname = path.dirname(
1111
fileURLToPath(

docs/.vitepress/theme/components/playground-block.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@
4949
import PgEditor from "./components/PgEditor.vue"
5050
import RulesSettings from "./components/RulesSettings.vue"
5151
import SnsBar from "./components/SnsBar.vue"
52-
import { deserializeState, serializeState } from "./state"
5352
import { DEFAULT_RULES_CONFIG, getRule } from "./rules"
53+
import { deserializeState, serializeState } from "./state"
5454
5555
const DEFAULT_CODE = String.raw`
5656
/eslint-plugin[-regexp]/u

lib/all-rules.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { RuleModule } from "./types"
21
import confusingQuantifier from "./rules/confusing-quantifier"
32
import controlCharacterEscape from "./rules/control-character-escape"
43
import graphemeStringLiteral from "./rules/grapheme-string-literal"
@@ -80,6 +79,7 @@ import sortFlags from "./rules/sort-flags"
8079
import strict from "./rules/strict"
8180
import unicodeEscape from "./rules/unicode-escape"
8281
import useIgnoreCase from "./rules/use-ignore-case"
82+
import type { RuleModule } from "./types"
8383

8484
export const rules: RuleModule[] = [
8585
confusingQuantifier,

lib/configs/rules/all.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { rules as recommendedRules } from "./recommended"
21
import { rules as ruleLint } from "../../all-rules"
2+
import { rules as recommendedRules } from "./recommended"
33

44
const all: Record<string, string> = {}
55
for (const rule of ruleLint) {

lib/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import type { RuleModule } from "./types"
21
import { rules as ruleList } from "./all-rules"
3-
import * as recommended from "./configs/recommended"
42
import * as all from "./configs/all"
5-
import * as flatRecommended from "./configs/flat/recommended"
63
import * as flatAll from "./configs/flat/all"
4+
import * as flatRecommended from "./configs/flat/recommended"
5+
import * as recommended from "./configs/recommended"
6+
import type { RuleModule } from "./types"
77
export * as meta from "./meta"
88

99
export const configs = {

lib/rules/confusing-quantifier.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { RegExpVisitor } from "@eslint-community/regexpp/visitor"
2+
import { isPotentiallyEmpty } from "regexp-ast-analysis"
23
import type { RegExpContext } from "../utils"
34
import { createRule, defineRegexpVisitor } from "../utils"
4-
import { isPotentiallyEmpty } from "regexp-ast-analysis"
55
import { quantToString, getQuantifierOffsets } from "../utils/regexp-ast"
66

77
export default createRule("confusing-quantifier", {

lib/rules/control-character-escape.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { PatternRange } from "../utils/ast-utils/pattern-source"
21
import type { RegExpVisitor } from "@eslint-community/regexpp/visitor"
32
import type { RegExpContext } from "../utils"
43
import {
@@ -10,6 +9,7 @@ import {
109
createRule,
1110
defineRegexpVisitor,
1211
} from "../utils"
12+
import type { PatternRange } from "../utils/ast-utils/pattern-source"
1313
import { isRegexpLiteral } from "../utils/ast-utils/utils"
1414
import { mentionChar } from "../utils/mention"
1515

lib/rules/grapheme-string-literal.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import type { StringAlternative } from "@eslint-community/regexpp/ast"
12
import type { RegExpVisitor } from "@eslint-community/regexpp/visitor"
23
import type { RegExpContext } from "../utils"
34
import { createRule, defineRegexpVisitor } from "../utils"
4-
import type { StringAlternative } from "@eslint-community/regexpp/ast"
55

66
const segmenter = new Intl.Segmenter()
77

lib/rules/hexadecimal-escape.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { RegExpVisitor } from "@eslint-community/regexpp/visitor"
21
import type { Character } from "@eslint-community/regexpp/ast"
2+
import type { RegExpVisitor } from "@eslint-community/regexpp/visitor"
33
import type { RegExpContext } from "../utils"
44
import { defineRegexpVisitor, createRule } from "../utils"
55
import {

lib/rules/letter-case.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import type { RegExpVisitor } from "@eslint-community/regexpp/visitor"
21
import type {
32
Character,
43
CharacterClassRange,
54
} from "@eslint-community/regexpp/ast"
5+
import type { RegExpVisitor } from "@eslint-community/regexpp/visitor"
66
import type { RegExpContext } from "../utils"
77
import {
88
createRule,

lib/rules/match-any.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import type { RegExpVisitor } from "@eslint-community/regexpp/visitor"
2-
import type { Rule } from "eslint"
31
import type {
42
CharacterClass,
53
ExpressionCharacterClass,
64
Node,
75
} from "@eslint-community/regexpp/ast"
6+
import type { RegExpVisitor } from "@eslint-community/regexpp/visitor"
7+
import type { Rule } from "eslint"
8+
import { matchesAllCharacters, hasStrings } from "regexp-ast-analysis"
89
import type { RegExpContext } from "../utils"
910
import { createRule, defineRegexpVisitor } from "../utils"
1011
import { isRegexpLiteral } from "../utils/ast-utils/utils"
11-
import { matchesAllCharacters, hasStrings } from "regexp-ast-analysis"
1212
import { mention } from "../utils/mention"
1313

1414
const OPTION_SS1 = "[\\s\\S]" as const

lib/rules/negation.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { toUnicodeSet } from "regexp-ast-analysis"
21
import type {
32
CharacterClass,
43
CharacterClassElement,
@@ -7,6 +6,7 @@ import type {
76
ExpressionCharacterClass,
87
} from "@eslint-community/regexpp/ast"
98
import type { RegExpVisitor } from "@eslint-community/regexpp/visitor"
9+
import { toUnicodeSet } from "regexp-ast-analysis"
1010
import type { RegExpContext } from "../utils"
1111
import { createRule, defineRegexpVisitor } from "../utils"
1212
import { assertNever } from "../utils/util"

lib/rules/no-contradiction-with-assertion.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
import type { RegExpVisitor } from "@eslint-community/regexpp/visitor"
21
import type {
32
Assertion,
43
Element,
54
Alternative,
65
Quantifier,
76
} from "@eslint-community/regexpp/ast"
8-
import type { RegExpContext } from "../utils"
9-
import { createRule, defineRegexpVisitor } from "../utils"
7+
import type { RegExpVisitor } from "@eslint-community/regexpp/visitor"
108
import type {
119
FirstLookChar,
1210
MatchingDirection,
@@ -21,8 +19,10 @@ import {
2119
isZeroLength,
2220
FirstConsumedChars,
2321
} from "regexp-ast-analysis"
24-
import { quantToString } from "../utils/regexp-ast"
22+
import type { RegExpContext } from "../utils"
23+
import { createRule, defineRegexpVisitor } from "../utils"
2524
import { mention } from "../utils/mention"
25+
import { quantToString } from "../utils/regexp-ast"
2626

2727
/**
2828
* Returns whether the given assertions is guaranteed to always trivially

lib/rules/no-control-character.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { mentionChar, mention } from "../utils/mention"
2-
import { CP_TAB, CP_LF, CP_VT, CP_FF, CP_CR } from "../utils/unicode"
1+
import type { Character } from "@eslint-community/regexpp/ast"
32
import type { RegExpVisitor } from "@eslint-community/regexpp/visitor"
3+
import type { Rule } from "eslint"
44
import type { RegExpContext } from "../utils"
55
import { createRule, defineRegexpVisitor } from "../utils"
6-
import type { Character } from "@eslint-community/regexpp/ast"
7-
import type { Rule } from "eslint"
6+
import { mentionChar, mention } from "../utils/mention"
7+
import { CP_TAB, CP_LF, CP_VT, CP_FF, CP_CR } from "../utils/unicode"
88

99
const CONTROL_CHARS = new Map<number, string>([
1010
[0, "\\0"],

lib/rules/no-dupe-characters-character-class.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { RegExpVisitor } from "@eslint-community/regexpp/visitor"
21
import type {
32
CharacterClass,
43
CharacterClassElement,
@@ -12,18 +11,19 @@ import type {
1211
ClassStringDisjunction,
1312
ExpressionCharacterClass,
1413
} from "@eslint-community/regexpp/ast"
15-
import type { RegExpContext } from "../utils"
14+
import type { RegExpVisitor } from "@eslint-community/regexpp/visitor"
15+
import type { CharRange, CharSet } from "refa"
16+
import { JS } from "refa"
17+
import type { ReadonlyFlags } from "regexp-ast-analysis"
18+
import { toCharSet, toUnicodeSet } from "regexp-ast-analysis"
1619
import {
1720
createRule,
1821
defineRegexpVisitor,
1922
fixRemoveCharacterClassElement,
2023
} from "../utils"
21-
import { toCharSetSource, assertValidFlags } from "../utils/refa"
22-
import type { CharRange, CharSet } from "refa"
23-
import { JS } from "refa"
24-
import type { ReadonlyFlags } from "regexp-ast-analysis"
25-
import { toCharSet, toUnicodeSet } from "regexp-ast-analysis"
24+
import type { RegExpContext } from "../utils"
2625
import { mentionChar } from "../utils/mention"
26+
import { toCharSetSource, assertValidFlags } from "../utils/refa"
2727
import { assertNever } from "../utils/util"
2828

2929
interface Grouping {

lib/rules/no-dupe-disjunctions.ts

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { RegExpVisitor } from "@eslint-community/regexpp/visitor"
21
import type {
32
Alternative,
43
CapturingGroup,
@@ -9,15 +8,8 @@ import type {
98
Pattern,
109
Quantifier,
1110
} from "@eslint-community/regexpp/ast"
12-
import type { RegExpContext } from "../utils"
13-
import {
14-
createRule,
15-
defineRegexpVisitor,
16-
fixRemoveCharacterClassElement,
17-
fixRemoveAlternative,
18-
fixRemoveStringAlternative,
19-
} from "../utils"
20-
import { isCoveredNode, isEqualNodes } from "../utils/regexp-ast"
11+
import type { RegExpVisitor } from "@eslint-community/regexpp/visitor"
12+
import type { Rule } from "eslint"
2113
import type { Expression, FiniteAutomaton, NoParent, ReadonlyNFA } from "refa"
2214
import {
2315
Transformers,
@@ -36,14 +28,22 @@ import {
3628
getEffectiveMaximumRepetition,
3729
canReorder,
3830
} from "regexp-ast-analysis"
31+
import type { RegExpContext } from "../utils"
32+
import {
33+
createRule,
34+
defineRegexpVisitor,
35+
fixRemoveCharacterClassElement,
36+
fixRemoveAlternative,
37+
fixRemoveStringAlternative,
38+
} from "../utils"
39+
import { getAllowedCharRanges, inRange } from "../utils/char-ranges"
3940
import { UsageOfPattern } from "../utils/get-usage-of-pattern"
4041
import { mention, mentionChar } from "../utils/mention"
4142
import type { NestedAlternative } from "../utils/partial-parser"
4243
import { PartialParser } from "../utils/partial-parser"
43-
import type { Rule } from "eslint"
44-
import { getAllowedCharRanges, inRange } from "../utils/char-ranges"
45-
import { assertNever } from "../utils/util"
4644
import { getParser, assertValidFlags } from "../utils/refa"
45+
import { isCoveredNode, isEqualNodes } from "../utils/regexp-ast"
46+
import { assertNever } from "../utils/util"
4747

4848
type ParentNode = Group | CapturingGroup | Pattern | LookaroundAssertion
4949

lib/rules/no-empty-alternative.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import type { RegExpVisitor } from "@eslint-community/regexpp/visitor"
21
import type {
32
Alternative,
43
CapturingGroup,
54
ClassStringDisjunction,
65
Group,
76
Pattern,
87
} from "@eslint-community/regexpp/ast"
8+
import type { RegExpVisitor } from "@eslint-community/regexpp/visitor"
99
import type { RegExpContext } from "../utils"
1010
import { createRule, defineRegexpVisitor } from "../utils"
1111

lib/rules/no-empty-capturing-group.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { isZeroLength } from "regexp-ast-analysis"
21
import type { RegExpVisitor } from "@eslint-community/regexpp/visitor"
2+
import { isZeroLength } from "regexp-ast-analysis"
33
import type { RegExpContext } from "../utils"
44
import { createRule, defineRegexpVisitor } from "../utils"
55

lib/rules/no-empty-character-class.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { matchesNoCharacters } from "regexp-ast-analysis"
21
import type { RegExpVisitor } from "@eslint-community/regexpp/visitor"
2+
import { matchesNoCharacters } from "regexp-ast-analysis"
33
import type { RegExpContext } from "../utils"
44
import { createRule, defineRegexpVisitor } from "../utils"
55

lib/rules/no-empty-group.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { RegExpVisitor } from "@eslint-community/regexpp/visitor"
21
import type { Group, CapturingGroup } from "@eslint-community/regexpp/ast"
2+
import type { RegExpVisitor } from "@eslint-community/regexpp/visitor"
33
import type { RegExpContext } from "../utils"
44
import { createRule, defineRegexpVisitor } from "../utils"
55

lib/rules/no-empty-lookarounds-assertion.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { isPotentiallyEmpty } from "regexp-ast-analysis"
21
import type { RegExpVisitor } from "@eslint-community/regexpp/visitor"
2+
import { isPotentiallyEmpty } from "regexp-ast-analysis"
33
import type { RegExpContext } from "../utils"
44
import { createRule, defineRegexpVisitor } from "../utils"
55

lib/rules/no-lazy-ends.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import type { RegExpVisitor } from "@eslint-community/regexpp/visitor"
21
import type { Alternative, Quantifier } from "@eslint-community/regexpp/ast"
3-
import type { RegExpContext } from "../utils"
2+
import type { RegExpVisitor } from "@eslint-community/regexpp/visitor"
43
import type { Rule } from "eslint"
4+
import type { RegExpContext } from "../utils"
55
import { createRule, defineRegexpVisitor } from "../utils"
66
import { UsageOfPattern } from "../utils/get-usage-of-pattern"
77

lib/rules/no-legacy-features.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type { MemberExpression } from "estree"
2-
import type { TYPES } from "@eslint-community/eslint-utils"
3-
import { READ, ReferenceTracker } from "@eslint-community/eslint-utils"
42
import { createRule } from "../utils"
53
import { createTypeTracker } from "../utils/type-tracker"
4+
import type { TYPES } from "@eslint-community/eslint-utils"
5+
import { READ, ReferenceTracker } from "@eslint-community/eslint-utils"
66

77
type StaticProperty =
88
| "input"

lib/rules/no-misleading-capturing-group.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
/* eslint-disable eslint-comments/disable-enable-pair -- x */
22

3-
import type { RegExpVisitor } from "@eslint-community/regexpp/visitor"
43
import type {
54
Alternative,
65
CapturingGroup,
76
Element,
87
Quantifier,
98
} from "@eslint-community/regexpp/ast"
10-
import type { RegExpContext } from "../utils"
11-
import { createRule, defineRegexpVisitor } from "../utils"
9+
import type { RegExpVisitor } from "@eslint-community/regexpp/visitor"
10+
import { CharSet } from "refa"
1211
import type { MatchingDirection, ReadonlyFlags } from "regexp-ast-analysis"
1312
import {
1413
isPotentiallyZeroLength,
@@ -20,12 +19,13 @@ import {
2019
followPaths,
2120
toUnicodeSet,
2221
} from "regexp-ast-analysis"
23-
import { canSimplifyQuantifier, hasCapturingGroup } from "../utils/regexp-ast"
22+
import type { RegExpContext } from "../utils"
23+
import { createRule, defineRegexpVisitor } from "../utils"
2424
import { fixSimplifyQuantifier } from "../utils/fix-simplify-quantifier"
2525
import { joinEnglishList, mention } from "../utils/mention"
2626
import { getParser, toCharSetSource } from "../utils/refa"
27+
import { canSimplifyQuantifier, hasCapturingGroup } from "../utils/regexp-ast"
2728
import { assertNever, cachedFn, reversed } from "../utils/util"
28-
import { CharSet } from "refa"
2929

3030
/**
3131
* Returns all quantifiers that are always at the start of the given element.

0 commit comments

Comments
 (0)