diff --git a/README.md b/README.md index 2398ee5..f4eb749 100644 --- a/README.md +++ b/README.md @@ -21,9 +21,9 @@ ESLint plugin to ensure consistent react imports ✅ Set in the `recommended` configuration.\ 🔧 Automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/user-guide/command-line-interface#--fix). -| Name   | Description | 💼 | 🔧 | -| :----------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------- | :- | :- | -| [syntax](docs/rules/syntax.md) | Enforces React import style across your code. Can be customized to use default or namespace import. By default converts exports using namespace import | ✅ | 🔧 | +| Name              | Description | 💼 | 🔧 | +| :--------------------------------------------------- | :-------------------------------------------------------------------------------------------------- | :- | :- | +| [consistent-syntax](docs/rules/consistent-syntax.md) | Enforces React import style across your code. Can be customized to use default or namespace import. | ✅ | 🔧 | diff --git a/docs/rules/syntax.md b/docs/rules/consistent-syntax.md similarity index 87% rename from docs/rules/syntax.md rename to docs/rules/consistent-syntax.md index 24e17cd..7cecab4 100644 --- a/docs/rules/syntax.md +++ b/docs/rules/consistent-syntax.md @@ -1,4 +1,4 @@ -# Enforces React import style across your code. Can be customized to use default or namespace import. (`react-import/syntax`) +# Enforces React import style across your code. Can be customized to use default or namespace import (`react-import/consistent-syntax`) 💼 This rule is enabled in the ✅ `recommended` config. @@ -21,7 +21,7 @@ import * as React from "react"; ## Options ```text -"react-import/syntax": [, <'namespace' | 'default'>] +"react-import/consistent-syntax": [, <'namespace' | 'default'>] ``` This rule has one string options that allows to choose the preferred syntax for React imports: diff --git a/src/configs/recommended.ts b/src/configs/recommended.ts index 7d97a28..90231bf 100644 --- a/src/configs/recommended.ts +++ b/src/configs/recommended.ts @@ -13,7 +13,7 @@ export const createRecommendedConfig = (options: { "react-import": plugin, }, rules: { - "react-import/syntax": ["error", "namespace"], + "react-import/consistent-syntax": ["error", "namespace"], }, languageOptions: { parserOptions: { diff --git a/src/eslintPluginReactImport.ts b/src/eslintPluginReactImport.ts index f44d45d..147deff 100644 --- a/src/eslintPluginReactImport.ts +++ b/src/eslintPluginReactImport.ts @@ -1,6 +1,6 @@ import type { ESLint, Linter } from "eslint"; -import syntaxRule from "./rules/syntax.js"; +import consistentSyntaxRule from "./rules/consistent-syntax.js"; import { createRecommendedConfig } from "./configs/recommended.js"; import { PLUGIN_NAME, PLUGIN_VERSION } from "./meta.js"; @@ -12,7 +12,7 @@ const eslintPluginReactImport = { }, configs: {} as { recommended: Linter.Config }, rules: { - syntax: syntaxRule, + "consistent-syntax": consistentSyntaxRule, }, processors: {}, } satisfies ESLint.Plugin; diff --git a/src/rules/syntax.spec.ts b/src/rules/consistent-syntax.spec.ts similarity index 99% rename from src/rules/syntax.spec.ts rename to src/rules/consistent-syntax.spec.ts index 1becd82..4c447a5 100644 --- a/src/rules/syntax.spec.ts +++ b/src/rules/consistent-syntax.spec.ts @@ -2,7 +2,7 @@ import { describe } from "vitest"; import { RuleTester } from "eslint"; import typescriptEslintParser from "@typescript-eslint/parser"; -import syntaxRule from "./syntax.js"; +import syntaxRule from "./consistent-syntax.js"; describe("syntax rule js", () => { const ruleTester = new RuleTester(); diff --git a/src/rules/syntax.ts b/src/rules/consistent-syntax.ts similarity index 99% rename from src/rules/syntax.ts rename to src/rules/consistent-syntax.ts index e7ec2eb..1182bd9 100644 --- a/src/rules/syntax.ts +++ b/src/rules/consistent-syntax.ts @@ -14,7 +14,7 @@ const syntaxRule: Rule.RuleModule = { "Enforces React import style across your code.", "Can be customized to use default or namespace import.", ].join(" "), - url: getRuleURL("syntax"), + url: getRuleURL("consistent-syntax"), }, messages: { wrongImport: "You should import React using {{syntax}} syntax", diff --git a/tests/__snapshots__/recommended-ts.spec.ts.snap b/tests/__snapshots__/recommended-ts.spec.ts.snap index 24c8f84..2f20a7a 100644 --- a/tests/__snapshots__/recommended-ts.spec.ts.snap +++ b/tests/__snapshots__/recommended-ts.spec.ts.snap @@ -17,7 +17,7 @@ exports[`config recommended > should have errors for invalid > should have 3 err "message": "You should import React using namespace syntax", "messageId": "wrongImport", "nodeType": null, - "ruleId": "react-import/syntax", + "ruleId": "react-import/consistent-syntax", "severity": 2, }, { @@ -35,7 +35,7 @@ exports[`config recommended > should have errors for invalid > should have 3 err "message": "This React import should have a 'React.' prefix", "messageId": "addPrefix", "nodeType": null, - "ruleId": "react-import/syntax", + "ruleId": "react-import/consistent-syntax", "severity": 2, }, { @@ -53,7 +53,7 @@ exports[`config recommended > should have errors for invalid > should have 3 err "message": "This React import should have a 'React.' prefix", "messageId": "addPrefix", "nodeType": null, - "ruleId": "react-import/syntax", + "ruleId": "react-import/consistent-syntax", "severity": 2, }, ] @@ -76,7 +76,7 @@ exports[`config recommended > should raise error when having two imports (1 valu "message": "You should import React using namespace syntax", "messageId": "wrongImport", "nodeType": null, - "ruleId": "react-import/syntax", + "ruleId": "react-import/consistent-syntax", "severity": 2, }, { @@ -94,7 +94,7 @@ exports[`config recommended > should raise error when having two imports (1 valu "message": "React was already imported. This import should be removed when using namespace import", "messageId": "duplicateImport", "nodeType": null, - "ruleId": "react-import/syntax", + "ruleId": "react-import/consistent-syntax", "severity": 2, }, { @@ -112,7 +112,7 @@ exports[`config recommended > should raise error when having two imports (1 valu "message": "This React import should have a 'React.' prefix", "messageId": "addPrefix", "nodeType": null, - "ruleId": "react-import/syntax", + "ruleId": "react-import/consistent-syntax", "severity": 2, }, { @@ -130,7 +130,7 @@ exports[`config recommended > should raise error when having two imports (1 valu "message": "This React import should have a 'React.' prefix", "messageId": "addPrefix", "nodeType": null, - "ruleId": "react-import/syntax", + "ruleId": "react-import/consistent-syntax", "severity": 2, }, ] @@ -153,7 +153,7 @@ exports[`config recommended > should raise error when renaming a named import of "message": "You should import React using namespace syntax", "messageId": "wrongImport", "nodeType": null, - "ruleId": "react-import/syntax", + "ruleId": "react-import/consistent-syntax", "severity": 2, }, { @@ -171,7 +171,7 @@ exports[`config recommended > should raise error when renaming a named import of "message": "This React import should have a 'React.' prefix", "messageId": "addPrefix", "nodeType": null, - "ruleId": "react-import/syntax", + "ruleId": "react-import/consistent-syntax", "severity": 2, }, ] diff --git a/tests/__snapshots__/recommended.spec.ts.snap b/tests/__snapshots__/recommended.spec.ts.snap index 44b2611..cca9776 100644 --- a/tests/__snapshots__/recommended.spec.ts.snap +++ b/tests/__snapshots__/recommended.spec.ts.snap @@ -17,7 +17,7 @@ exports[`config recommended > should have errors for invalid > should have 2 err "message": "You should import React using namespace syntax", "messageId": "wrongImport", "nodeType": null, - "ruleId": "react-import/syntax", + "ruleId": "react-import/consistent-syntax", "severity": 2, }, { @@ -35,7 +35,7 @@ exports[`config recommended > should have errors for invalid > should have 2 err "message": "This React import should have a 'React.' prefix", "messageId": "addPrefix", "nodeType": null, - "ruleId": "react-import/syntax", + "ruleId": "react-import/consistent-syntax", "severity": 2, }, ] @@ -58,7 +58,7 @@ exports[`config recommended > should raise error when renaming a named import of "message": "You should import React using namespace syntax", "messageId": "wrongImport", "nodeType": null, - "ruleId": "react-import/syntax", + "ruleId": "react-import/consistent-syntax", "severity": 2, }, { @@ -76,7 +76,7 @@ exports[`config recommended > should raise error when renaming a named import of "message": "This React import should have a 'React.' prefix", "messageId": "addPrefix", "nodeType": null, - "ruleId": "react-import/syntax", + "ruleId": "react-import/consistent-syntax", "severity": 2, }, ]