Skip to content

Add eslint-plugin-import #711

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = {
"plugin:@ota-meshi/+yaml",
// "plugin:@ota-meshi/+md",
"plugin:@ota-meshi/+prettier",
"plugin:import/recommended",
"plugin:regexp/recommended",
],
rules: {
Expand Down Expand Up @@ -73,6 +74,8 @@ module.exports = {
},
],

"import/order": ["warn", { alphabetize: { order: "asc" } }],

// regexp next recommended
"regexp/no-contradiction-with-assertion": "error",
"regexp/no-empty-character-class": "error",
Expand Down Expand Up @@ -118,6 +121,12 @@ module.exports = {
"no-implicit-globals": "off",
"@typescript-eslint/naming-convention": "off",
},
settings: {
"import/resolver": {
typescript: true,
node: true,
},
},
},
{
files: ["lib/rules/**"],
Expand Down Expand Up @@ -148,6 +157,8 @@ module.exports = {
rules: {
"vue/multi-word-component-names": "off",
"@typescript-eslint/no-explicit-any": "off",
"import/named": "off",
"import/no-unresolved": "off",
},
},
{
Expand Down
4 changes: 2 additions & 2 deletions docs/.vitepress/build-system/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
* Pre-build cjs packages that cannot be bundled well.
*/

import esbuild from "esbuild"
import path from "path"
import fs from "fs"
import path from "path"
import { fileURLToPath } from "url"
import esbuild from "esbuild"

const dirname = path.dirname(
fileURLToPath(
Expand Down
2 changes: 1 addition & 1 deletion docs/.vitepress/theme/components/playground-block.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
import PgEditor from "./components/PgEditor.vue"
import RulesSettings from "./components/RulesSettings.vue"
import SnsBar from "./components/SnsBar.vue"
import { deserializeState, serializeState } from "./state"
import { DEFAULT_RULES_CONFIG, getRule } from "./rules"
import { deserializeState, serializeState } from "./state"

const DEFAULT_CODE = String.raw`
/eslint-plugin[-regexp]/u
Expand Down
2 changes: 1 addition & 1 deletion lib/all-rules.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { RuleModule } from "./types"
import confusingQuantifier from "./rules/confusing-quantifier"
import controlCharacterEscape from "./rules/control-character-escape"
import graphemeStringLiteral from "./rules/grapheme-string-literal"
Expand Down Expand Up @@ -80,6 +79,7 @@ import sortFlags from "./rules/sort-flags"
import strict from "./rules/strict"
import unicodeEscape from "./rules/unicode-escape"
import useIgnoreCase from "./rules/use-ignore-case"
import type { RuleModule } from "./types"

export const rules: RuleModule[] = [
confusingQuantifier,
Expand Down
2 changes: 1 addition & 1 deletion lib/configs/rules/all.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { rules as recommendedRules } from "./recommended"
import { rules as ruleLint } from "../../all-rules"
import { rules as recommendedRules } from "./recommended"

const all: Record<string, string> = {}
for (const rule of ruleLint) {
Expand Down
6 changes: 3 additions & 3 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { RuleModule } from "./types"
import { rules as ruleList } from "./all-rules"
import * as recommended from "./configs/recommended"
import * as all from "./configs/all"
import * as flatRecommended from "./configs/flat/recommended"
import * as flatAll from "./configs/flat/all"
import * as flatRecommended from "./configs/flat/recommended"
import * as recommended from "./configs/recommended"
import type { RuleModule } from "./types"
export * as meta from "./meta"

export const configs = {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/confusing-quantifier.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { RegExpVisitor } from "@eslint-community/regexpp/visitor"
import { isPotentiallyEmpty } from "regexp-ast-analysis"
import type { RegExpContext } from "../utils"
import { createRule, defineRegexpVisitor } from "../utils"
import { isPotentiallyEmpty } from "regexp-ast-analysis"
import { quantToString, getQuantifierOffsets } from "../utils/regexp-ast"

export default createRule("confusing-quantifier", {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/control-character-escape.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { PatternRange } from "../utils/ast-utils/pattern-source"
import type { RegExpVisitor } from "@eslint-community/regexpp/visitor"
import type { RegExpContext } from "../utils"
import {
Expand All @@ -10,6 +9,7 @@ import {
createRule,
defineRegexpVisitor,
} from "../utils"
import type { PatternRange } from "../utils/ast-utils/pattern-source"
import { isRegexpLiteral } from "../utils/ast-utils/utils"
import { mentionChar } from "../utils/mention"

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/grapheme-string-literal.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { StringAlternative } from "@eslint-community/regexpp/ast"
import type { RegExpVisitor } from "@eslint-community/regexpp/visitor"
import type { RegExpContext } from "../utils"
import { createRule, defineRegexpVisitor } from "../utils"
import type { StringAlternative } from "@eslint-community/regexpp/ast"

const segmenter = new Intl.Segmenter()

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/hexadecimal-escape.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { RegExpVisitor } from "@eslint-community/regexpp/visitor"
import type { Character } from "@eslint-community/regexpp/ast"
import type { RegExpVisitor } from "@eslint-community/regexpp/visitor"
import type { RegExpContext } from "../utils"
import { defineRegexpVisitor, createRule } from "../utils"
import {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/letter-case.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { RegExpVisitor } from "@eslint-community/regexpp/visitor"
import type {
Character,
CharacterClassRange,
} from "@eslint-community/regexpp/ast"
import type { RegExpVisitor } from "@eslint-community/regexpp/visitor"
import type { RegExpContext } from "../utils"
import {
createRule,
Expand Down
6 changes: 3 additions & 3 deletions lib/rules/match-any.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import type { RegExpVisitor } from "@eslint-community/regexpp/visitor"
import type { Rule } from "eslint"
import type {
CharacterClass,
ExpressionCharacterClass,
Node,
} from "@eslint-community/regexpp/ast"
import type { RegExpVisitor } from "@eslint-community/regexpp/visitor"
import type { Rule } from "eslint"
import { matchesAllCharacters, hasStrings } from "regexp-ast-analysis"
import type { RegExpContext } from "../utils"
import { createRule, defineRegexpVisitor } from "../utils"
import { isRegexpLiteral } from "../utils/ast-utils/utils"
import { matchesAllCharacters, hasStrings } from "regexp-ast-analysis"
import { mention } from "../utils/mention"

const OPTION_SS1 = "[\\s\\S]" as const
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/negation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { toUnicodeSet } from "regexp-ast-analysis"
import type {
CharacterClass,
CharacterClassElement,
Expand All @@ -7,6 +6,7 @@ import type {
ExpressionCharacterClass,
} from "@eslint-community/regexpp/ast"
import type { RegExpVisitor } from "@eslint-community/regexpp/visitor"
import { toUnicodeSet } from "regexp-ast-analysis"
import type { RegExpContext } from "../utils"
import { createRule, defineRegexpVisitor } from "../utils"
import { assertNever } from "../utils/util"
Expand Down
8 changes: 4 additions & 4 deletions lib/rules/no-contradiction-with-assertion.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import type { RegExpVisitor } from "@eslint-community/regexpp/visitor"
import type {
Assertion,
Element,
Alternative,
Quantifier,
} from "@eslint-community/regexpp/ast"
import type { RegExpContext } from "../utils"
import { createRule, defineRegexpVisitor } from "../utils"
import type { RegExpVisitor } from "@eslint-community/regexpp/visitor"
import type {
FirstLookChar,
MatchingDirection,
Expand All @@ -21,8 +19,10 @@ import {
isZeroLength,
FirstConsumedChars,
} from "regexp-ast-analysis"
import { quantToString } from "../utils/regexp-ast"
import type { RegExpContext } from "../utils"
import { createRule, defineRegexpVisitor } from "../utils"
import { mention } from "../utils/mention"
import { quantToString } from "../utils/regexp-ast"

/**
* Returns whether the given assertions is guaranteed to always trivially
Expand Down
8 changes: 4 additions & 4 deletions lib/rules/no-control-character.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { mentionChar, mention } from "../utils/mention"
import { CP_TAB, CP_LF, CP_VT, CP_FF, CP_CR } from "../utils/unicode"
import type { Character } from "@eslint-community/regexpp/ast"
import type { RegExpVisitor } from "@eslint-community/regexpp/visitor"
import type { Rule } from "eslint"
import type { RegExpContext } from "../utils"
import { createRule, defineRegexpVisitor } from "../utils"
import type { Character } from "@eslint-community/regexpp/ast"
import type { Rule } from "eslint"
import { mentionChar, mention } from "../utils/mention"
import { CP_TAB, CP_LF, CP_VT, CP_FF, CP_CR } from "../utils/unicode"

const CONTROL_CHARS = new Map<number, string>([
[0, "\\0"],
Expand Down
14 changes: 7 additions & 7 deletions lib/rules/no-dupe-characters-character-class.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { RegExpVisitor } from "@eslint-community/regexpp/visitor"
import type {
CharacterClass,
CharacterClassElement,
Expand All @@ -12,18 +11,19 @@ import type {
ClassStringDisjunction,
ExpressionCharacterClass,
} from "@eslint-community/regexpp/ast"
import type { RegExpContext } from "../utils"
import type { RegExpVisitor } from "@eslint-community/regexpp/visitor"
import type { CharRange, CharSet } from "refa"
import { JS } from "refa"
import type { ReadonlyFlags } from "regexp-ast-analysis"
import { toCharSet, toUnicodeSet } from "regexp-ast-analysis"
import {
createRule,
defineRegexpVisitor,
fixRemoveCharacterClassElement,
} from "../utils"
import { toCharSetSource, assertValidFlags } from "../utils/refa"
import type { CharRange, CharSet } from "refa"
import { JS } from "refa"
import type { ReadonlyFlags } from "regexp-ast-analysis"
import { toCharSet, toUnicodeSet } from "regexp-ast-analysis"
import type { RegExpContext } from "../utils"
import { mentionChar } from "../utils/mention"
import { toCharSetSource, assertValidFlags } from "../utils/refa"
import { assertNever } from "../utils/util"

interface Grouping {
Expand Down
26 changes: 13 additions & 13 deletions lib/rules/no-dupe-disjunctions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { RegExpVisitor } from "@eslint-community/regexpp/visitor"
import type {
Alternative,
CapturingGroup,
Expand All @@ -9,15 +8,8 @@ import type {
Pattern,
Quantifier,
} from "@eslint-community/regexpp/ast"
import type { RegExpContext } from "../utils"
import {
createRule,
defineRegexpVisitor,
fixRemoveCharacterClassElement,
fixRemoveAlternative,
fixRemoveStringAlternative,
} from "../utils"
import { isCoveredNode, isEqualNodes } from "../utils/regexp-ast"
import type { RegExpVisitor } from "@eslint-community/regexpp/visitor"
import type { Rule } from "eslint"
import type { Expression, FiniteAutomaton, NoParent, ReadonlyNFA } from "refa"
import {
Transformers,
Expand All @@ -36,14 +28,22 @@ import {
getEffectiveMaximumRepetition,
canReorder,
} from "regexp-ast-analysis"
import type { RegExpContext } from "../utils"
import {
createRule,
defineRegexpVisitor,
fixRemoveCharacterClassElement,
fixRemoveAlternative,
fixRemoveStringAlternative,
} from "../utils"
import { getAllowedCharRanges, inRange } from "../utils/char-ranges"
import { UsageOfPattern } from "../utils/get-usage-of-pattern"
import { mention, mentionChar } from "../utils/mention"
import type { NestedAlternative } from "../utils/partial-parser"
import { PartialParser } from "../utils/partial-parser"
import type { Rule } from "eslint"
import { getAllowedCharRanges, inRange } from "../utils/char-ranges"
import { assertNever } from "../utils/util"
import { getParser, assertValidFlags } from "../utils/refa"
import { isCoveredNode, isEqualNodes } from "../utils/regexp-ast"
import { assertNever } from "../utils/util"

type ParentNode = Group | CapturingGroup | Pattern | LookaroundAssertion

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-empty-alternative.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { RegExpVisitor } from "@eslint-community/regexpp/visitor"
import type {
Alternative,
CapturingGroup,
ClassStringDisjunction,
Group,
Pattern,
} from "@eslint-community/regexpp/ast"
import type { RegExpVisitor } from "@eslint-community/regexpp/visitor"
import type { RegExpContext } from "../utils"
import { createRule, defineRegexpVisitor } from "../utils"

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-empty-capturing-group.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isZeroLength } from "regexp-ast-analysis"
import type { RegExpVisitor } from "@eslint-community/regexpp/visitor"
import { isZeroLength } from "regexp-ast-analysis"
import type { RegExpContext } from "../utils"
import { createRule, defineRegexpVisitor } from "../utils"

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-empty-character-class.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { matchesNoCharacters } from "regexp-ast-analysis"
import type { RegExpVisitor } from "@eslint-community/regexpp/visitor"
import { matchesNoCharacters } from "regexp-ast-analysis"
import type { RegExpContext } from "../utils"
import { createRule, defineRegexpVisitor } from "../utils"

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-empty-group.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { RegExpVisitor } from "@eslint-community/regexpp/visitor"
import type { Group, CapturingGroup } from "@eslint-community/regexpp/ast"
import type { RegExpVisitor } from "@eslint-community/regexpp/visitor"
import type { RegExpContext } from "../utils"
import { createRule, defineRegexpVisitor } from "../utils"

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-empty-lookarounds-assertion.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isPotentiallyEmpty } from "regexp-ast-analysis"
import type { RegExpVisitor } from "@eslint-community/regexpp/visitor"
import { isPotentiallyEmpty } from "regexp-ast-analysis"
import type { RegExpContext } from "../utils"
import { createRule, defineRegexpVisitor } from "../utils"

Expand Down
4 changes: 2 additions & 2 deletions lib/rules/no-lazy-ends.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { RegExpVisitor } from "@eslint-community/regexpp/visitor"
import type { Alternative, Quantifier } from "@eslint-community/regexpp/ast"
import type { RegExpContext } from "../utils"
import type { RegExpVisitor } from "@eslint-community/regexpp/visitor"
import type { Rule } from "eslint"
import type { RegExpContext } from "../utils"
import { createRule, defineRegexpVisitor } from "../utils"
import { UsageOfPattern } from "../utils/get-usage-of-pattern"

Expand Down
4 changes: 2 additions & 2 deletions lib/rules/no-legacy-features.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { MemberExpression } from "estree"
import type { TYPES } from "@eslint-community/eslint-utils"
import { READ, ReferenceTracker } from "@eslint-community/eslint-utils"
import { createRule } from "../utils"
import { createTypeTracker } from "../utils/type-tracker"
import type { TYPES } from "@eslint-community/eslint-utils"
import { READ, ReferenceTracker } from "@eslint-community/eslint-utils"

type StaticProperty =
| "input"
Expand Down
10 changes: 5 additions & 5 deletions lib/rules/no-misleading-capturing-group.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
/* eslint-disable eslint-comments/disable-enable-pair -- x */

import type { RegExpVisitor } from "@eslint-community/regexpp/visitor"
import type {
Alternative,
CapturingGroup,
Element,
Quantifier,
} from "@eslint-community/regexpp/ast"
import type { RegExpContext } from "../utils"
import { createRule, defineRegexpVisitor } from "../utils"
import type { RegExpVisitor } from "@eslint-community/regexpp/visitor"
import { CharSet } from "refa"
import type { MatchingDirection, ReadonlyFlags } from "regexp-ast-analysis"
import {
isPotentiallyZeroLength,
Expand All @@ -20,12 +19,13 @@ import {
followPaths,
toUnicodeSet,
} from "regexp-ast-analysis"
import { canSimplifyQuantifier, hasCapturingGroup } from "../utils/regexp-ast"
import type { RegExpContext } from "../utils"
import { createRule, defineRegexpVisitor } from "../utils"
import { fixSimplifyQuantifier } from "../utils/fix-simplify-quantifier"
import { joinEnglishList, mention } from "../utils/mention"
import { getParser, toCharSetSource } from "../utils/refa"
import { canSimplifyQuantifier, hasCapturingGroup } from "../utils/regexp-ast"
import { assertNever, cachedFn, reversed } from "../utils/util"
import { CharSet } from "refa"

/**
* Returns all quantifiers that are always at the start of the given element.
Expand Down
Loading