Skip to content

Commit

Permalink
fix: allow for better handling of javascript files
Browse files Browse the repository at this point in the history
  • Loading branch information
mscharley committed Oct 7, 2024
1 parent 4872523 commit 7d2169b
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 20 deletions.
5 changes: 5 additions & 0 deletions .changeset/big-parrots-peel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@mscharley/eslint-config': patch
---

Prevent better support for linting JS files
26 changes: 11 additions & 15 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
import { configs as mscharley, withStyles } from '@mscharley/eslint-config';
import { configs as tseslint } from 'typescript-eslint';
import { disableTypeCheckedRules, configs as mscharley, withStyles } from '@mscharley/eslint-config';

const c = [
...mscharley.recommended,
...withStyles(),
{
ignores: ['**/dist/**'],
},
{
files: [
// No global typescript project
'*.js',
// Most eslint plugins don't bother with typescript types which causes issues.
'presets/eslint/rules/**/*.js',
// Prettier doesn't have a typescript project
'presets/prettier/**/*.js',
// Disable for config files in the root of the commands
'commands/*/*.js',
],
...tseslint.disableTypeChecked,
},
disableTypeCheckedRules(
// No global typescript project
'*.js',
// Most eslint plugins don't bother with typescript types which causes issues.
'presets/eslint/rules/**/*.js',
// Prettier doesn't have a typescript project
'presets/prettier/**/*.js',
// Disable for config files in the root of the commands
'commands/*/*.js',
),
];

export default c;
8 changes: 8 additions & 0 deletions presets/eslint/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ If using Prettier to format files other than TypeScript and JavaScript files the
**/*.js
```

### Usage in JavaScript projects

```
Parsing error: [...]/configFile.js was not found by the project service. Consider either including it in the tsconfig.json or including it in allowDefaultProject
```

If you get messages like this, you can disable type-checked rules using the `disableTypeCheckedRules()` helper function exported by this module. This takes a list of file paths and returns a single configuration object. This takes into account all type checked rules enabled by this configuration and is a superset of the helper configuration provided by `typescript-eslint` for a similar purpose.

[gh-contrib]: https://github.com/mscharley/node-presets/graphs/contributors
[gh-issues]: https://github.com/mscharley/node-presets/issues
[license]: https://github.com/mscharley/node-presets/blob/main/LICENSE
6 changes: 4 additions & 2 deletions presets/eslint/rules/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import typescript, { disableTypeCheckedRules } from './typescript.js';
import eslint from './eslint.js';
import node from './node.js';
import react from './react.js';
import stylistic from '@stylistic/eslint-plugin';
import testing from './testing.js';
import typescript from './typescript.js';

export const configs = {
recommended: [
Expand Down Expand Up @@ -37,4 +37,6 @@ export const withStyles = () => [
},
];

export default { configs, withStyles };
export { disableTypeCheckedRules };

export default { configs, disableTypeCheckedRules, withStyles };
19 changes: 16 additions & 3 deletions presets/eslint/rules/typescript.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import { configs as tseslint } from 'typescript-eslint';

export const disableTypeCheckedRules = (...files) => ({
files,
...tseslint.disableTypeChecked,
rules: {
...tseslint.disableTypeChecked.rules,
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
},
});

/** @type import('eslint').Config[] */
export default [
...tseslint.recommendedTypeChecked,
Expand All @@ -11,9 +21,6 @@ export default [
},
},
{
files: [
'**/*.ts', '**/*.tsx', '**/*.mts', '**/*.cts',
],
rules: {
'@typescript-eslint/no-deprecated': 'warn',
'@typescript-eslint/array-type': [
Expand Down Expand Up @@ -128,8 +135,13 @@ export default [
'@typescript-eslint/no-unused-vars': [
'warn',
{
args: 'all',
argsIgnorePattern: '^_',
caughtErrors: 'all',
caughtErrorsIgnorePattern: '^_',
destructuredArrayIgnorePattern: '^_',
varsIgnorePattern: '^_',
ignoreRestSiblings: true,
},
],
'@typescript-eslint/no-unnecessary-boolean-literal-compare': [
Expand Down Expand Up @@ -174,4 +186,5 @@ export default [
'@typescript-eslint/switch-exhaustiveness-check': 'error',
},
},
disableTypeCheckedRules('*.config.js'),
];

0 comments on commit 7d2169b

Please sign in to comment.