Skip to content

Commit

Permalink
feat: add enableJavaScriptSpecificRulesInTypeScriptProject createCo…
Browse files Browse the repository at this point in the history
…nfig argument

- `enableJavaScriptSpecificRulesInTypeScriptProject` skips disabling JS specific rules that are shadowed by typescript in situations where you still want to fully lint JS files but cannot use checkJs in tsconfig
  • Loading branch information
ljosberinn committed Aug 8, 2022
1 parent 43e5dae commit 309c7a4
Show file tree
Hide file tree
Showing 14 changed files with 1,859 additions and 25 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,28 @@ This way, you can customize it entirely to your likings without having to create

</details>

<details>
<summary>Migrating a codebase to TypeScript</summary>

While in the process of migration, you may end up in a situation where you cannot turn on `compilerOptions.checkJs` from TypeScript itself due to e.g. builds breaking. However, by default certain rules will be disabled for JavaScript files because they are technically shadowed by TypeScript itself, e.g. `no-undef`.

You can opt out of this behaviour by either:

- passing `enableJavaScriptSpecificRulesInTypeScriptProject` as `true` to `createConfig`
- enabling `compilerOptions.checkJs` once you're there

Example:

```js
const { createConfig } = require('eslint-config-galex/dist/createConfig');

module.exports = createConfig({
enableJavaScriptSpecificRulesInTypeScriptProject: true,
});
```

</details>

# Examples

<details>
Expand Down
4 changes: 4 additions & 0 deletions __tests__/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ const cases = [
name: 'js ts migration mix checkJs on',
path: 'js-ts-migration-mix-checkJs-on',
},
{
name: 'js ts migration force js linting in ts',
path: 'js-ts-migration-mix-force-js-linting',
},
];

describe.each(cases)('$case.name', ({ path, name }) => {
Expand Down
11 changes: 11 additions & 0 deletions integration/abstractConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,20 @@ if (!process.argv.some(arg => arg.includes('vscode-eslint'))) {
parser: 'json-stringify',
};

let extraArgs = {};

if (process.env.createConfigArgs) {
extraArgs = JSON.parse(process.env.createConfigArgs);

console.log(
`running createConfig with extra arguments: ${process.env.createConfigArgs}`
);
}

const config = createConfig({
root: true,
cwd,
...extraArgs,
});

const depsPath = resolve('deps.json');
Expand Down
4 changes: 4 additions & 0 deletions integration/js-ts-migration-mix-force-js-linting/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
process.env.createConfigArgs = JSON.stringify({
enableJavaScriptSpecificRulesInTypeScriptProject: true,
});
module.exports = require('../abstractConfig');
49 changes: 49 additions & 0 deletions integration/js-ts-migration-mix-force-js-linting/deps.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"hasJest": false,
"hasJestDom": false,
"hasNodeTypes": false,
"hasTestingLibrary": false,
"hasNest": false,
"storybook": {
"hasStorybook": false,
"hasStorybookTestingLibrary": false
},
"react": {
"hasReact": false,
"isCreateReactApp": false,
"isNext": false,
"isRemix": false,
"isPreact": false,
"version": null
},
"typescript": {
"config": {
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true
},
"include": [
"src"
],
"exclude": [
"node_modules"
]
},
"hasTypeScript": true,
"version": "4.6.4"
}
}
Loading

0 comments on commit 309c7a4

Please sign in to comment.