Skip to content
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

chore: unify load-rules.ts and utils/rules.ts to rules/index.ts #438

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion docs-build/src/components/eslint/scripts/linter.mts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { rules as pluginRules } from "../../../../../src/utils/rules.js"
import { rules as pluginRules } from "../../../../../src/rules"
import type { Linter, Rule } from "eslint"
import { builtinRules } from "eslint/use-at-your-own-risk"
import * as astroEslintParser from "astro-eslint-parser"
Expand Down
2 changes: 1 addition & 1 deletion docs-build/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { rules } from "../../src/utils/rules"
import { rules } from "../../src/rules"

const categories = [
"Possible Errors",
Expand Down
2 changes: 1 addition & 1 deletion src/configs/all.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import recommended from "./recommended"
import { rules } from "../utils/rules"
import { rules } from "../rules"

const all: Record<string, string> = {}
for (const rule of rules.filter(
Expand Down
2 changes: 1 addition & 1 deletion src/configs/flat/all.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import recommended from "./recommended"
import { rules } from "../../utils/rules"
import { rules } from "../../rules"

const all: Record<string, string> = {}
for (const rule of rules.filter(
Expand Down
2 changes: 1 addition & 1 deletion src/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { rules as ruleList } from "./utils/rules"
import { rules as ruleList } from "./rules"
import * as processorsDefines from "./processor"
import type { Rule } from "eslint"
import { name, version } from "./meta"
Expand Down
39 changes: 39 additions & 0 deletions src/rules/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import missingClientOnlyDirectiveValue from "./missing-client-only-directive-value"
import noConflictSetDirectives from "./no-conflict-set-directives"
import noDeprecatedAstroCanonicalUrl from "./no-deprecated-astro-canonicalurl"
import noDeprecatedAstroFetchContent from "./no-deprecated-astro-fetchcontent"
import noDeprecatedAstroResolve from "./no-deprecated-astro-resolve"
import noDeprecatedGetEntryBySlug from "./no-deprecated-getentrybyslug"
import noExportsFromComponents from "./no-exports-from-components"
import noSetHtmlDirective from "./no-set-html-directive"
import noSetTextDirective from "./no-set-text-directive"
import noUnusedCssSelector from "./no-unused-css-selector"
import noUnusedDefineVarsInStyle from "./no-unused-define-vars-in-style"
import preferClassListDirective from "./prefer-class-list-directive"
import preferObjectClassList from "./prefer-object-class-list"
import preferSplitClassList from "./prefer-split-class-list"
import semi from "./semi"
import sortAttributes from "./sort-attributes"
import validCompile from "./valid-compile"
import { buildA11yRules } from "../a11y"

export const originalRules = [
missingClientOnlyDirectiveValue,
noConflictSetDirectives,
noDeprecatedAstroCanonicalUrl,
noDeprecatedAstroFetchContent,
noDeprecatedAstroResolve,
noDeprecatedGetEntryBySlug,
noExportsFromComponents,
noSetHtmlDirective,
noSetTextDirective,
noUnusedCssSelector,
noUnusedDefineVarsInStyle,
preferClassListDirective,
preferObjectClassList,
preferSplitClassList,
semi,
sortAttributes,
validCompile,
]
export const rules = [...originalRules, ...buildA11yRules()]
43 changes: 0 additions & 43 deletions src/utils/rules.ts

This file was deleted.

39 changes: 39 additions & 0 deletions tests/src/rules/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { readdirSync } from "fs"
import { join } from "path"
import assert from "assert"
import { rules } from "../../../src/rules/index"
import { buildA11yRules } from "src/a11y"

describe("Test src/rules/index.ts", () => {
function getImportedRuleNames() {
return rules.map((rule) => rule.meta.docs.ruleName)
}

function assertRulesImported(rulesToCheck: string[]) {
const importedRules = getImportedRuleNames()
rulesToCheck.forEach((ruleName) => {
assert(
importedRules.includes(ruleName),
`Imported rules should include ${ruleName}`,
)
})
}

it("should import all rule files", () => {
const rulesDir = join(__dirname, "../../../src/rules")
const ruleFiles = readdirSync(rulesDir)
.filter(
(file) =>
file.endsWith(".ts") &&
file !== "index.ts" &&
!file.endsWith(".test.ts"),
)
.map((file) => file.replace(".ts", ""))
assertRulesImported(ruleFiles)
})

it("should import all a11y rules", () => {
const a11yRules = buildA11yRules().map((rule) => rule.meta.docs.ruleName)
assertRulesImported(a11yRules)
})
})
2 changes: 1 addition & 1 deletion tests/src/rules/jsx-a11y/aria-proptypes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { RuleTester } from "../../../utils/eslint-compat"
import { rules } from "../../../../src/utils/rules"
import { rules } from "../../../../src/rules"
import { loadTestCases } from "../../../utils/utils"

const rule = rules.find(
Expand Down
2 changes: 1 addition & 1 deletion tests/src/rules/jsx-a11y/heading-has-content.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { RuleTester } from "../../../utils/eslint-compat"
import { rules } from "../../../../src/utils/rules"
import { rules } from "../../../../src/rules"
import { loadTestCases } from "../../../utils/utils"

const rule = rules.find(
Expand Down
2 changes: 1 addition & 1 deletion tests/src/rules/jsx-a11y/label-has-associated-control.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { RuleTester } from "../../../utils/eslint-compat"
import { rules } from "../../../../src/utils/rules"
import { rules } from "../../../../src/rules"
import { loadTestCases } from "../../../utils/utils"

const rule = rules.find(
Expand Down
2 changes: 1 addition & 1 deletion tests/src/rules/jsx-a11y/no-autofocus.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { RuleTester } from "../../../utils/eslint-compat"
import { rules } from "../../../../src/utils/rules"
import { rules } from "../../../../src/rules"
import { loadTestCases } from "../../../utils/utils"

const rule = rules.find(
Expand Down
21 changes: 0 additions & 21 deletions tools/lib/load-rules.ts

This file was deleted.

2 changes: 1 addition & 1 deletion tools/render-rules-table.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// eslint-disable-next-line @eslint-community/eslint-comments/disable-enable-pair -- ignore
/* eslint-disable func-style -- Arrow functions are better when returning string */
import type { RuleCategory, RuleModule } from "../src/types"
import { rules } from "../src/utils/rules"
import { rules } from "../src/rules"

const categories: RuleCategory[] = [
"Possible Errors",
Expand Down
2 changes: 1 addition & 1 deletion tools/update-docs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from "path"
import fs from "fs"
import { rules } from "../src/utils/rules"
import { rules } from "../src/rules"
import type { RuleModule } from "../src/types"
import { getNewVersion } from "./lib/changesets-util"
import { formatAndSave } from "./lib/utils"
Expand Down
37 changes: 0 additions & 37 deletions tools/update-rules.ts

This file was deleted.

2 changes: 1 addition & 1 deletion tools/update-rulesets.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from "path"
import { rules } from "./lib/load-rules"
import { originalRules as rules } from "../src/rules"
import { formatAndSave } from "./lib/utils"

const baseRules = rules.filter(
Expand Down
1 change: 0 additions & 1 deletion tools/update.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import "./update-rules"
import "./update-rulesets"
import "./update-docs"
import "./update-readme"
Expand Down
Loading