Skip to content

Commit

Permalink
feat: reenabled import checking rules (eslint-plugin-import) (#197)
Browse files Browse the repository at this point in the history
* feat: reenabled import checking rules (eslint-plugin-import)

Signed-off-by: Jérôme Benoit <[email protected]>

* refactor: enable eslint-plugin-import TS support

Signed-off-by: Jérôme Benoit <[email protected]>

* fix: add eslint-import-resolver-typescript as a dep

Signed-off-by: Jérôme Benoit <[email protected]>

* refactor: cleanup dependents-data

Signed-off-by: Jérôme Benoit <[email protected]>

---------

Signed-off-by: Jérôme Benoit <[email protected]>
  • Loading branch information
jerome-benoit authored Dec 9, 2024
1 parent cb93f15 commit 629e936
Show file tree
Hide file tree
Showing 7 changed files with 295 additions and 15 deletions.
3 changes: 3 additions & 0 deletions .knip.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"index.js",
"index.d.ts"
],
"ignoreDependencies": [
"eslint-import-resolver-typescript"
],
"ignore": [
"test/should-*/**/*",
"test/ts-extension-eslint.config.mjs"
Expand Down
7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ module.exports = require('neostandard')({
#### List of exported plugins

* `@stylistic` - export of [`@stylistic/eslint-plugin`](https://npmjs.com/package/@stylistic/eslint-plugin)
* `import` - export of [`eslint-plugin-import`](https://npmjs.com/package/eslint-plugin-import)
* `n` - export of [`eslint-plugin-n`](https://npmjs.com/package/eslint-plugin-n)
* `promise` - export of [`eslint-plugin-promise`](https://npmjs.com/package/eslint-plugin-promise)
* `react` - export of [`eslint-plugin-react`](https://npmjs.com/package/eslint-plugin-react)
Expand All @@ -179,7 +180,6 @@ export default [

## Missing for 1.0.0 release

* Migrate `eslint-plugin-import` rules from `standard`: [#15](https://github.com/neostandard/neostandard/issues/15)
* Investigate a dedicated `neostandard` runner: [#33](https://github.com/neostandard/neostandard/issues/33) / [#2](https://github.com/neostandard/neostandard/issues/2)

Full list in [1.0.0 milestone](https://github.com/neostandard/neostandard/milestone/1)
Expand All @@ -203,11 +203,6 @@ Full list in [1.0.0 milestone](https://github.com/neostandard/neostandard/milest
* [`dot-notation`](https://eslint.org/docs/rules/dot-notation)*deactivated* – clashes with the [`noPropertyAccessFromIndexSignature`](https://www.typescriptlang.org/tsconfig#noPropertyAccessFromIndexSignature) check in TypeScript
* [`n/no-deprecated-api`](https://github.com/eslint-community/eslint-plugin-n/blob/master/docs/rules/no-deprecated-api.md)*changed* – changed to `warn` instead of `error` as they are not urgent to fix

### Missing bits

* Some plugins are not yet supporting ESLint 9 or flat configs and has thus not yet been added. These are:
- `eslint-plugin-import`

## Config helper

You can use the provided CLI tool to generate a config for you:
Expand Down
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ module.exports.plugins = /** @type {const} */ ({
get '@stylistic' () {
return require('@stylistic/eslint-plugin')
},
get import () {
// @ts-ignore
return require('eslint-plugin-import')
},
get n () {
return require('eslint-plugin-n')
},
Expand Down
17 changes: 9 additions & 8 deletions lib/configs/base.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict'

const globals = require('globals')
// @ts-ignore
const eslintPluginImport = require('eslint-plugin-import')
const eslintPluginN = require('eslint-plugin-n')
// @ts-ignore
const eslintPluginPromise = require('eslint-plugin-promise')
Expand All @@ -21,8 +23,7 @@ module.exports = /** @satisfies {import('eslint').Linter.Config} */ ({
},

plugins: {
// TODO: Replace with https://github.com/un-ts/eslint-plugin-import-x, but do it in a way that works for the TS-config as well: https://github.com/un-ts/eslint-plugin-import-x?tab=readme-ov-file#typescript
// 'import',
import: eslintPluginImport,
n: eslintPluginN,
promise: eslintPluginPromise,
},
Expand Down Expand Up @@ -149,12 +150,12 @@ module.exports = /** @satisfies {import('eslint').Linter.Config} */ ({
'valid-typeof': ['error', { requireStringLiterals: true }],
yoda: ['error', 'never'],

// 'import/export': 'error',
// 'import/first': 'error',
// 'import/no-absolute-path': ['error', { 'esmodule': true, 'commonjs': true, 'amd': false }],
// 'import/no-duplicates': 'error',
// 'import/no-named-default': 'error',
// 'import/no-webpack-loader-syntax': 'error',
'import/export': 'error',
'import/first': 'error',
'import/no-absolute-path': ['error', { esmodule: true, commonjs: true, amd: false }],
'import/no-duplicates': 'error',
'import/no-named-default': 'error',
'import/no-webpack-loader-syntax': 'error',

// TODO: Should only be active for server side scripts
'n/handle-callback-err': ['error', '^(err|error)$'],
Expand Down
6 changes: 6 additions & 0 deletions lib/ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ function typescriptify (configs, options) {
// @ts-ignore - Plugin type mismatch between typescript-eslint and ESLint
'@typescript-eslint': plugin,
},
settings: {
'import/resolver': {
typescript: true,
node: true,
},
},
rules: {
...deactivatedRules,
...replacementRules,
Expand Down
Loading

0 comments on commit 629e936

Please sign in to comment.