Skip to content

Commit

Permalink
Merge pull request #1519 from mightyiam/no-at-types-eslint
Browse files Browse the repository at this point in the history
chore(deps): use eslint types from tseslint
  • Loading branch information
mightyiam committed Apr 11, 2024
2 parents 86c56a3 + 1a5c434 commit 2812e60
Show file tree
Hide file tree
Showing 9 changed files with 189 additions and 70 deletions.
212 changes: 160 additions & 52 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
"@commitlint/config-conventional": "19.1.0",
"@semantic-release/changelog": "6.0.3",
"@semantic-release/git": "10.0.1",
"@types/eslint": "8.56.8",
"@types/js-yaml": "4.0.9",
"@types/lodash": "4.17.0",
"@types/node": "20.12.7",
Expand All @@ -76,6 +75,7 @@
"@typescript-eslint_bottom/eslint-plugin": "npm:@typescript-eslint/eslint-plugin@7.0.1",
"@typescript-eslint_bottom/parser": "npm:@typescript-eslint/parser@7.0.1",
"@typescript-eslint/eslint-plugin": "7.6.0",
"@typescript-eslint/utils": "7.6.0",
"@ungap/structured-clone": "1.2.0",
"ava": "6.1.2",
"editorconfig-checker": "5.1.5",
Expand Down
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Linter } from 'eslint'
import { TSESLint } from '@typescript-eslint/utils'

const rules = {
'@typescript-eslint/adjacent-overload-signatures': ['error'],
Expand Down Expand Up @@ -391,9 +391,9 @@ const rules = {
'n/process-exit-as-throw': ['error'],

'promise/param-names': ['error']
} satisfies Linter.RulesRecord
} satisfies TSESLint.ClassicConfig.RulesRecord

const eslintRuleNames = [...(new Linter()).getRules().keys()]
const eslintRuleNames = [...(new TSESLint.Linter()).getRules().keys()]
const namesOfEslintRulesForWhichWeAreUsingTsEquivalents = eslintRuleNames
.filter(name => Object.hasOwn(rules, `@typescript-eslint/${name}`))

Expand All @@ -413,6 +413,6 @@ const config = {
...rules
}

} satisfies Linter.Config
} satisfies TSESLint.ClassicConfig.Config

export = config
8 changes: 4 additions & 4 deletions src/test/_util.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import exported from '..'
import { rules as typescriptEslintRules } from '@typescript-eslint/eslint-plugin'
import { Linter } from 'eslint'
import { TSESLint } from '@typescript-eslint/utils'
import semver from 'semver'
import { type PackageJson } from 'type-fest'

Expand Down Expand Up @@ -43,11 +43,11 @@ export const isPinnedRange = (rangeStr: string): boolean => {

export const extractVersionSpec = (range: string): string => range.split('@').slice(-1)[0]

const ourRules_: Linter.Config['rules'] = exported.rules
const ourRules_: TSESLint.ClassicConfig.RulesRecord = exported.rules
if (ourRules_ === undefined) throw new Error('we seem to be exporting no rules')
export const ourRules = ourRules_

export const equivalents = [...(new Linter()).getRules().keys()]
export const equivalents = [...(new TSESLint.Linter()).getRules().keys()]
.filter(name => Object.prototype.hasOwnProperty.call(typescriptEslintRules, name))

export const typescriptEslintBottom = '@typescript-eslint_bottom'
Expand Down Expand Up @@ -449,4 +449,4 @@ export const expectedExportedValue = {
'@typescript-eslint/type-annotation-spacing': ['error'],
'@typescript-eslint/unbound-method': ['error', { ignoreStatic: false }]
}
} satisfies Linter.BaseConfig
} satisfies TSESLint.ClassicConfig.Config
4 changes: 2 additions & 2 deletions src/test/compatibility.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import test from 'ava'
import { ESLint } from 'eslint'
import { TSESLint } from '@typescript-eslint/utils'
import exported from '..'
import semver from 'semver'
import { extractVersionSpec, getPkgDetails, ourRules, typescriptEslintBottom } from './_util'
Expand Down Expand Up @@ -44,7 +44,7 @@ test('our configuration is compatible with the plugin and parser at bottom of pe
}
}

const eslint = new ESLint({
const eslint = new TSESLint.ESLint({
useEslintrc: false,
overrideConfig: config
})
Expand Down
9 changes: 9 additions & 0 deletions src/test/dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,12 @@ test('devDep plugin range subset of dep parser range', async (t) => {
if (depParserRange === undefined) throw new Error()
t.true(semver.subset(devPluginRange, depParserRange))
})

test('devDep @typescript-eslint/utils range equals devDep plugin range', async (t) => {
const { ourDevDeps } = await getPkgDetails()
const devPluginRange = ourDevDeps['@typescript-eslint/eslint-plugin']
const devUtilsRange = ourDevDeps['@typescript-eslint/utils']
if (devPluginRange === undefined) throw new Error()
if (devUtilsRange === undefined) throw new Error()
t.true(semver.subset(devUtilsRange, devPluginRange))
})
4 changes: 2 additions & 2 deletions src/test/parser-options.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import test from 'ava'
import { type Linter } from 'eslint'
import { type TSESLint } from '@typescript-eslint/utils'
import exported from '..'

test('export', (t): void => {
const expectedParserOptions = {
project: true
} satisfies Linter.BaseConfig['parserOptions']
} satisfies TSESLint.ClassicConfig.ParserOptions

t.deepEqual(exported.parserOptions, expectedParserOptions, 'parserOptions')
})

0 comments on commit 2812e60

Please sign in to comment.