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: move 'utils/rules.ts' to 'rules/index.ts' #439

Merged
merged 1 commit into from
Oct 27, 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
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
42 changes: 42 additions & 0 deletions src/rules/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// IMPORTANT!
// This file has been automatically generated by "update-rules-index.ts",
// in order to update its content, update "update-rules-index.ts" and execute "npm run update"
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.

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
7 changes: 6 additions & 1 deletion tools/lib/load-rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ function readRules(): RuleModule[] {
const rulesPath = path.resolve(__dirname, "../../src/rules")
return fs
.readdirSync(rulesPath)
.filter((n) => n.endsWith(".ts"))
.filter((n) => n.endsWith(".ts") && n !== "index.ts")
.map((fileName) => require(path.join(rulesPath, fileName)).default)
}

/**
* This array is designed primarily for generator scripts in the "tools/" folder.
* It does not include extended rules (such as `a11y` rules).
* For a complete set of rules, consider using the generated file `rules/index.ts` instead.
*/
export const rules = readRules()
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
38 changes: 38 additions & 0 deletions tools/update-rules-index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import path from "path"
import { rules } from "./lib/load-rules"
import { formatAndSave } from "./lib/utils"

/**
* Convert text to camelCase
*/
function camelCase(str: string) {
return str.replace(/[-_](\w)/gu, (_, c) => (c ? c.toUpperCase() : ""))
}

/**
* Map rule name to import statement
*/
function mapRuleNameToImport(name: string) {
return `import ${camelCase(name)} from "./${name}"`
}

const currentFileName = path.basename(__filename)
const ruleNames = rules.map((rule) => rule.meta.docs.ruleName)
const content = `/*
* IMPORTANT!
* This file has been automatically generated by "${currentFileName}",
* in order to update its content, update "${currentFileName}" and execute "npm run update"
*/
${ruleNames.map(mapRuleNameToImport).join("\n")}
import { buildA11yRules } from "../a11y"

export const originalRules = [
${ruleNames.map(camelCase).join(",")},
]
export const rules = [...originalRules, ...buildA11yRules()]
`

const filePath = path.resolve(__dirname, "../src/rules/index.ts")

// Update file.
void formatAndSave(filePath, content)
37 changes: 0 additions & 37 deletions tools/update-rules.ts

This file was deleted.

2 changes: 1 addition & 1 deletion tools/update.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import "./update-rules"
import "./update-rules-index"
import "./update-rulesets"
import "./update-docs"
import "./update-readme"
Expand Down
Loading