Skip to content

Commit

Permalink
add eslint-plugin-import
Browse files Browse the repository at this point in the history
Fork because of a required fix that hasn't been shipped yet.
  • Loading branch information
slice committed Sep 14, 2024
1 parent 3ae875b commit 7703d75
Show file tree
Hide file tree
Showing 5 changed files with 362 additions and 4 deletions.
12 changes: 12 additions & 0 deletions .yarn/patches/eslint-plugin-import-https-251cd9e890.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/package.json b/package.json
index 85c863485b0c37df556132beddf7f6959e6b5961..c1bdec0cb02cbabda11a8917d37d3792134c81aa 100644
--- a/package.json
+++ b/package.json
@@ -21,6 +21,7 @@
"scripts": {
"prebuild": "rimraf lib",
"build": "babel --quiet --out-dir lib src",
+ "prepack": "yarn run build",
"postbuild": "npm run copy-metafiles",
"copy-metafiles": "node --require babel-register ./scripts/copyMetafiles",
"watch": "npm run tests-only -- -- --watch",
10 changes: 10 additions & 0 deletions eslint-plugin-react.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,13 @@ declare module 'eslint-plugin-react-hooks' {
}
export default plugin
}

// Non-exhaustive.
declare module 'eslint-plugin-import' {
import type { Linter } from 'eslint'

export const flatConfigs: {
typescript: Linter.Config
recommended: Linter.Config
}
}
50 changes: 50 additions & 0 deletions lib/basic.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,54 @@
// @ts-check

import { fileURLToPath } from 'node:url'
import path from 'node:path'

import { fixupPluginRules } from '@eslint/compat'
import { FlatCompat } from '@eslint/eslintrc'
import js from '@eslint/js'
import eslintPluginImport from 'eslint-plugin-import'

const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
})

// https://github.com/import-js/eslint-plugin-import/issues/2948#issuecomment-2148832701
/**
* @param {string} name
* @param {string} alias
* @returns {import('eslint').ESLint.Plugin}
*/
function legacyPlugin(name, alias = name) {
const plugin = compat.plugins(name)[0]?.plugins?.[alias]
if (!plugin) throw new Error(`Unable to resolve plugin ${name} and/or alias ${alias}`)
return fixupPluginRules(plugin)
}

/** @type {import('eslint').Linter.Config[]} */
export const importPlugin = [
{ ...eslintPluginImport.flatConfigs.recommended, plugins: {} },
// TypeScript one doesn't have a name, but recommended does.
{ ...eslintPluginImport.flatConfigs.typescript, name: 'import/typescript', plugins: {} },

{
name: '@textshq/eslint-config.basic.import',
plugins: { import: legacyPlugin('eslint-plugin-import', 'import') },
settings: {
'import/parsers': {
'@typescript-eslint/parser': ['.ts', '.tsx'],
},
'import/resolver': {
typescript: {
alwaysTryTypes: true,
},
node: true,
},
},
},
]

/** @satisfies {import('@typescript-eslint/utils/ts-eslint').FlatConfig.ConfigFile} */
const config = [
Expand Down Expand Up @@ -35,6 +83,8 @@ const config = [
'prefer-template': 'off',
},
},

...importPlugin,
]

export default config
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
"@stylistic/eslint-plugin": "^2.8.0",
"@typescript-eslint/eslint-plugin": "^8.5.0",
"@typescript-eslint/parser": "^8.5.0",
"eslint-import-resolver-typescript": "^3.6.3",
"eslint-plugin-import": "TextsHQ/eslint-plugin-import#commit=b271f426d6834ce802df68c1eea33b8cae895b26",
"eslint-plugin-jsx-a11y": "^6.10.0",
"eslint-plugin-react": "^7.36.1",
"eslint-plugin-react-hooks": "5.1.0-rc-206df66e-20240912",
Expand All @@ -24,7 +26,9 @@
},
"devDependencies": {
"@types/eslint-plugin-jsx-a11y": "^6",
"@types/eslint__eslintrc": "^2.1.2",
"@types/eslint__js": "^8.42.3",
"@types/node": "^18",
"eslint": "^9.10.0",
"typescript": "<5.6.0"
},
Expand Down
Loading

0 comments on commit 7703d75

Please sign in to comment.