Skip to content

Commit

Permalink
update linterOptions, fix react-typescript config, update README with…
Browse files Browse the repository at this point in the history
… file glob suggestions
  • Loading branch information
iamnapo committed May 26, 2024
1 parent afa687c commit c663122
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 23 deletions.
14 changes: 5 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,11 @@ Add to your `eslint.config.js` one of the available configs<sup>*</sup> like so:
import eslintConfigIamnapo from "eslint-config-iamnapo";

const config = [
{
files: [
"**/*.{c,m,}js",
// "**/*.{c,m,}jsx",
// "**/*.{c,m,}ts",
// "**/*.{c,m,}tsx"
],
},
...eslintConfigIamnapo.configs.default,
...eslintConfigIamnapo.configs.default.map(cfg => ({
...cfg,
files: ["**/*.{c,m,}js"], // or "**/*.{c,m,}js{x,}"
// files: ["**/*.{c,m,}ts"], // or "**/*.{c,m,}ts{x,}"
})),
// your overrides
];

Expand Down
3 changes: 2 additions & 1 deletion default.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ const config = [
"@stylistic": eslintPluginStylistic,
},
linterOptions: {
reportUnusedDisableDirectives: true,
noInlineConfig: true,
reportUnusedDisableDirectives: "error",
},
languageOptions: {
ecmaVersion: 15,
Expand Down
7 changes: 1 addition & 6 deletions react-typescript.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import { FlatCompat } from "@eslint/eslintrc";

import reactConfig from "./react.js";
import typescriptConfig from "./typescript.js";

const compat = new FlatCompat({ baseDirectory: import.meta.dirname });
import { configReact as typescriptConfig } from "./typescript.js";

/** @type {import("eslint").Linter.FlatConfig[]} */
const config = [
...reactConfig,
...compat.extends("airbnb-typescript"),
...typescriptConfig,
];

Expand Down
2 changes: 1 addition & 1 deletion test/react-typescript.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ test("load config in eslint to validate all rule syntax is correct", async () =>
`.replaceAll("\t", "");
const errorCount = await linter.verify(
code,
[{ files: ["**/*.{c,m,}tsx"] }, ...config],
config.map(cfg => ({ ...cfg, files: ["**/*.{c,m,}tsx"] })),
fileURLToPath(new URL("test.tsx", import.meta.url)),
);
assert.equal(errorCount.length, 6);
Expand Down
2 changes: 1 addition & 1 deletion test/react.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ test("load config in eslint to validate all rule syntax is correct", async () =>
`.replaceAll("\t", "");
const errorCount = await linter.verify(
code,
[{ files: ["**/*.{c,m,}jsx"] }, ...config, { rules: { "import/no-unresolved": "off" } }],
[...config.map(cfg => ({ ...cfg, files: ["**/*.{c,m,}jsx"] })), { rules: { "import/no-unresolved": "off" } }],
fileURLToPath(new URL("test.jsx", import.meta.url)),
);
assert.equal(errorCount.length, 0);
Expand Down
2 changes: 1 addition & 1 deletion test/typescript.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ test("load config in eslint to validate all rule syntax is correct", async () =>
`.replaceAll("\t", "");
const errorCount = await linter.verify(
code,
[{ files: ["**/*.{c,m,}ts"] }, ...config],
config.map(cfg => ({ ...cfg, files: ["**/*.{c,m,}ts"] })),
fileURLToPath(new URL("test.ts", import.meta.url)),
);
assert.equal(errorCount.length, 1);
Expand Down
9 changes: 5 additions & 4 deletions typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import defaultConfig from "./default.js";

const compat = new FlatCompat({ baseDirectory: import.meta.dirname });

/** @type {import("eslint").Linter.FlatConfig[]} */
const config = [
/** @type {(reactSupport?: boolean) => import("eslint").Linter.FlatConfig[]} */
const config = (reactSupport = false) => [
...defaultConfig,
...compat.extends("airbnb-typescript/base"),
...compat.extends(`airbnb-typescript${reactSupport ? "" : "/base"}`),
...tsEslint.configs.recommendedTypeChecked,
...tsEslint.configs.stylisticTypeChecked,
eslintPluginStylistic.configs["disable-legacy"],
Expand Down Expand Up @@ -37,4 +37,5 @@ const config = [
},
];

export default config;
export const configReact = config(true);
export default config(false);

0 comments on commit c663122

Please sign in to comment.