Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added .eslintrc
Empty file.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,18 @@ module.exports = [
}
}
];

```
## Opt-in unused export checking

If you'd like to opt-in to unused export linting, you can pass a third arg to `getTscLintingConfig` pointing to your sources, e.g.

```javascript
getTscLintingConfig(['node_modules/*'], globals.browser, ['src/**'])
```

Due to a current issue in the plugin used, this will require you to create a blank `.eslintrc` file, otherwise you'll get an error telling you to do so. :shrug:

## Integrating into your build

- Run eslint as part of your build to ensure your JavaScript is up to snuff!
Expand Down
2 changes: 1 addition & 1 deletion common-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ const styleRules = {
'@stylistic/comma-style': 'error',
'@stylistic/computed-property-spacing': 'error',
'@stylistic/dot-location': ['error', 'property'],
'@stylistic/func-call-spacing': 'error',
'@stylistic/function-call-spacing': 'error',
'@stylistic/function-call-argument-newline': ['error', 'consistent'],
'@stylistic/generator-star-spacing': 'error',
'@stylistic/indent': [
Expand Down
2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const getTscLintingConfig = require('./index');
const globals = require('globals');

module.exports = getTscLintingConfig(['node_modules/*'], globals.node);
module.exports = getTscLintingConfig(['node_modules/*'], globals.node, ['example-files/**']);
3 changes: 2 additions & 1 deletion example-files/js-file.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const a = () => 1;
// unused export
export const a = () => 1;

// magic number
a(5);
Expand Down
4 changes: 2 additions & 2 deletions example-files/ts-file.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// missing return type
const a = (b: number) => b + 1;
// missing return type, BUT this export is used in tsx-file
export const a = (b: number) => b + 1;

// magic number
a(5);
12 changes: 8 additions & 4 deletions example-files/tsx-file.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import {a} from './ts-file';

// missing return type
const a = (b: number) => b + 1;
const c = (b: number) => b + 1;

// magic number
a(5);
c(5);

a(0);

// unused, missing return type
const Component = () => (
// missing return type, unused export
export const Component = () => (
<>
<div>
Hello world!
Expand Down
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import eslint from 'eslint';

export default function(ignores: string[], globals: Record<string, false>): eslint.Linter.Config[];
export default function(ignores: string[], globals: Record<string, false>, srcForCheckingUnusedFiles?: string[]): eslint.Linter.Config[];
23 changes: 21 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ const reactHooksPlugin = require('eslint-plugin-react-hooks');
const preferArrowPlugin = require('eslint-plugin-prefer-arrow');
const tsEslint = require('typescript-eslint');
const stylisticPlugin = require('@stylistic/eslint-plugin');
const importPlugin = require('eslint-plugin-import-x');

module.exports = (ignores, globals) => [
module.exports = (ignores, globals, srcForCheckingUnusedFiles) => [
{
name: 'global ignores',
ignores: ignores
Expand All @@ -30,7 +31,25 @@ module.exports = (ignores, globals) => [
}, {
name: 'base js rules',
files: ['**/*.?(m|c)@(j|t)s?(x)'],
rules: commonRules
plugins: {'import-x': importPlugin},
rules: {
...commonRules,
...(srcForCheckingUnusedFiles
? {'import-x/no-unused-modules': ['error', {unusedExports: true, src: srcForCheckingUnusedFiles}]}
: {}
)
},
settings: {
'import-x/extensions': ['.js', '.jsx', '.ts', '.tsx'],
'import-x/parsers': {
'@typescript-eslint/parser': ['.ts', '.tsx']
},
'import-x/resolver': {
typescript: {
alwaysTryTypes: true
}
}
}
}, {
name: 'react rules',
files: ['**/*.?(m|c)jsx', '**/*.?(m|c)tsx'],
Expand Down
Loading