Skip to content

Commit

Permalink
docs: update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Rel1cx committed Jan 30, 2025
1 parent 2c77165 commit 76c6726
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,20 @@ import TSCONFIG from "./tsconfig.json" with { type: "json" };
import TSCONFIG_NODE from "./tsconfig.node.json" with { type: "json" };
import { isInEditorEnv } from "@eslint-react/shared";

const GLOB_TS = ["**/*.ts", "**/*.tsx"];
function getOptimalParserConfig(project = "tsconfig.json") {
switch (true) {
case isInEditorEnv():
case process.argv.includes("--fix"):
return {
parser: tseslint.parser,
parserOptions: {
project,
tsconfigRootDir: import.meta.dirname,
},
};
}
return { parser: tsBlankEslintParser };
}

export default [
// base configuration for browser environment source files
Expand All @@ -21,7 +34,7 @@ export default [
globals: {
...globals.browser,
},
...getOptimalParser(),
...getOptimalParserConfig(),
},
rules: {
...eslintJs.configs.recommended.rules,
Expand All @@ -35,7 +48,7 @@ export default [
globals: {
...globals.node,
},
...getOptimalParser("tsconfig.node.json"),
...getOptimalParserConfig("tsconfig.node.json"),
},
rules: {
...eslintJs.configs.recommended.rules,
Expand Down Expand Up @@ -66,25 +79,3 @@ export default [
},
},
];

function getOptimalParser(project = "tsconfig.json") {
return isFixable()
? {
parser: tseslint.parser,
parserOptions: {
project,
tsconfigRootDir: import.meta.dirname,
},
}
: {
parser: tsBlankEslintParser,
};
}

function isFixable() {
return isInEditorEnv() || hasFixFlag();
}

function hasFixFlag() {
return process.argv.includes("--fix");
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"eslint-plugin-react-refresh": "^0.4.18",
"globals": "^15.14.0",
"meriyah": "^6.0.5",
"ts-blank-eslint-parser": "^0.3.1",
"ts-blank-eslint-parser": "^0.3.2",
"ts-blank-space": "^0.5.1",
"typescript": "^5.7.3",
"typescript-eslint": "^8.22.0",
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -33,58 +33,46 @@ yarn add --dev eslint typescript-eslint @eslint/js globals ts-blank-eslint-parse
// @ts-check
import eslintJs from "@eslint/js";
import eslintReact from "@eslint-react/eslint-plugin";
import { isInEditorEnv } from "@eslint-react/shared";
import tsBlankEslintParser from "ts-blank-eslint-parser";
import tseslint from "typescript-eslint";
import globals from "globals";

import TSCONFIG from "./tsconfig.json" with { type: "json" };
import TSCONFIG_NODE from "./tsconfig.node.json" with { type: "json" };
import { isInEditorEnv } from "@eslint-react/shared";

const GLOB_TS = ["**/*.ts", "**/*.tsx"];

function getOptimalParserConfig(project = "tsconfig.json") {
switch (true) {
case isInEditorEnv():
case process.argv.includes("--fix"):
return {
parser: tseslint.parser,
parserOptions: {
project,
tsconfigRootDir: import.meta.dirname,
},
};
}
return { parser: tsBlankEslintParser };
}

export default [
// base configuration for browser environment source files
{
files: TSCONFIG.include,
files: GLOB_TS,
languageOptions: {
globals: {
...globals.browser,
},
...getOptimalParser(),
...getOptimalParserConfig(),
},
rules: {
...eslintJs.configs.recommended.rules,
},
},
// React configuration
{
files: TSCONFIG.include,
files: GLOB_TS,
...eslintReact.configs.recommended,
},
];

function getOptimalParser(project = "tsconfig.json") {
return !isFixable()
? {
// fast but no fixable support for types
parser: tsBlankEslintParser,
}
: {
// slow but needed for fixable to work
parser: tseslint.parser,
parserOptions: {
project,
tsconfigRootDir: import.meta.dirname,
},
};
}

function isFixable() {
return isInEditorEnv() || hasFixFlag();
}

function hasFixFlag() {
return process.argv.includes("--fix");
}
```

0 comments on commit 76c6726

Please sign in to comment.