Skip to content

Commit

Permalink
🐛 fix: editor env + bump deps
Browse files Browse the repository at this point in the history
Signed-off-by: Pauline <[email protected]>
  • Loading branch information
pauliesnug committed Aug 21, 2024
1 parent 4576aee commit f7c1d96
Show file tree
Hide file tree
Showing 7 changed files with 522 additions and 290 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"devDependencies": {
"@flowr/eslint-config": "workspace:^",
"@flowr/tsconfig": "workspace:^",
"@types/node": "^22.4.0",
"@types/node": "^22.5.0",
"bumpp": "^9.5.1",
"esbuild": "^0.23.1",
"eslint": "^9.9.0",
Expand All @@ -48,7 +48,7 @@
"tsx": "^4.17.0",
"typescript": "^5.5.4",
"unbuild": "^2.0.0",
"vite": "^5.4.1",
"vite": "^5.4.2",
"vitest": "^2.0.5"
}
}
4 changes: 2 additions & 2 deletions packages/eslint-config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ export default defineConfig({

certain rules are disabled when inside [eslint ide integrations](#ide-integration), namely [`unused-imports/no-unused-imports`] and [`petal/no-only-tests`].

this is to prevent unused imports and temporary patches from getting removed by the ide during refactoring. those rules are applied when eslint is ran in the terminal. you can disable this behavior using:
this is to prevent unused imports and temporary patches from getting removed by the ide during refactoring. those rules are applied when eslint is ran in the terminal. you can disable this behavior by manually setting `isInEditor`:

```js
// eslint.config.js
Expand All @@ -660,7 +660,7 @@ export default defineConfig({

## config inspector

eslint has a visual tool to help view what rules are enabled in a project and which files they are applied to, [`@eslint/config-inspector`]. go to the project root that contains a `eslint.config.js` file and run:
eslint has a visual tool to help view what rules are enabled in a project and which files they are applied to, [`@eslint/config-inspector`]. go to the project root that contains a `eslint.config` file and run:

```bash
pnpm dlx @eslint/config-inspector
Expand Down
14 changes: 7 additions & 7 deletions packages/eslint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,14 @@
}
},
"dependencies": {
"@antfu/install-pkg": "^0.3.5",
"@antfu/install-pkg": "^0.4.0",
"@clack/prompts": "^0.7.0",
"@eslint-community/eslint-plugin-eslint-comments": "^4.4.0",
"@stylistic/eslint-plugin": "^2.6.4",
"@typescript-eslint/eslint-plugin": "^8.1.0",
"@typescript-eslint/parser": "^8.1.0",
"@typescript-eslint/eslint-plugin": "^8.2.0",
"@typescript-eslint/parser": "^8.2.0",
"@vitest/eslint-plugin": "^1.0.3",
"eslint-flat-config-utils": "^0.3.0",
"eslint-flat-config-utils": "^0.3.1",
"eslint-merge-processors": "^0.1.0",
"eslint-plugin-command": "^0.2.3",
"eslint-plugin-import-x": "^3.1.0",
Expand All @@ -163,10 +163,10 @@
"yaml-eslint-parser": "^1.2.3"
},
"devDependencies": {
"@eslint-react/eslint-plugin": "^1.10.1",
"@eslint/config-inspector": "^0.5.3",
"@eslint-react/eslint-plugin": "^1.12.0",
"@eslint/config-inspector": "^0.5.4",
"@prettier/plugin-xml": "^3.4.1",
"@tanstack/eslint-plugin-query": "^5.51.15",
"@tanstack/eslint-plugin-query": "^5.52.0",
"@types/eslint": "^9.6.0",
"@types/eslint-plugin-jsx-a11y": "^6.9.0",
"@types/fs-extra": "^11.0.4",
Expand Down
9 changes: 8 additions & 1 deletion packages/eslint-config/src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ export function defineConfig(options: FactoryOptions = {}, ...userConfigs: UserC
autoRenamePlugins = true,
componentExts = [],
gitignore: enableGitignore = true,
isInEditor = isInEditorEnv(),
jsx: enableJsx = true,
query: enableQuery = QUERY_PACKAGES.some(pkgSort),
react: enableReact = REACT_PACKAGES.some(pkgSort),
Expand All @@ -101,6 +100,14 @@ export function defineConfig(options: FactoryOptions = {}, ...userConfigs: UserC
vue: enableVue = VUE_PACKAGES.some(pkgSort),
} = options;

let isInEditor = options.isInEditor;
if (isInEditor == null) {
isInEditor = isInEditorEnv();
if (isInEditor)
// eslint-disable-next-line no-console -- debug editor message
console.log('[@flowr/eslint-config]: running in editor - some rules ar disabled');
}

const stylisticOptions = options.stylistic === false
? false
: typeof options.stylistic === 'object'
Expand Down
23 changes: 22 additions & 1 deletion packages/eslint-config/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,25 @@ export function getOverrides<K extends keyof OptionsConfig>(options: OptionsConf
return { ...'overrides' in sub ? sub.overrides : {} };
}

export const isInEditorEnv = (): boolean => !!((process.env.VSCODE_PID || process.env.VSCODE_CWD || process.env.JETBRAINS_IDE || process.env.VIM || process.env.NVIM) && !process.env.CI);
export function isInEditorEnv(): boolean {
if (process.env.CI)
return false;
if (isInHook())
return false;

return !!(false
|| process.env.VSCODE_PID
|| process.env.VSCODE_CWD
|| process.env.JETBRAINS_IDE
|| process.env.VIM
|| process.env.NVIM
);
}

export function isInHook(): boolean {
return !!(false
|| process.env.GIT_PARAMS
|| process.env.VSCODE_GIT_COMMAND
|| process.env.npm_lifecycle_script?.startsWith('lint-staged')
);
}
2 changes: 1 addition & 1 deletion packages/eslint-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
},
"devDependencies": {
"@types/eslint": "^9.6.0",
"@typescript-eslint/utils": "^8.1.0",
"@typescript-eslint/utils": "^8.2.0",
"eslint": "9.9.0",
"eslint-vitest-rule-tester": "^0.6.1",
"jsonc-eslint-parser": "^2.4.0"
Expand Down
Loading

0 comments on commit f7c1d96

Please sign in to comment.