Skip to content

Commit 6cba8eb

Browse files
authored
feat: migrate to ESM primary (#271)
1 parent a2abfb6 commit 6cba8eb

File tree

170 files changed

+2990
-1451
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

170 files changed

+2990
-1451
lines changed

.changeset/thin-beans-speak.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-import-x": minor
3+
---
4+
5+
feat: migrate to ESM primary

.env.yarn

-2
This file was deleted.

.eslint-doc-generatorrc.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { format } from 'prettier'
2+
3+
import prettierRC from './.prettierrc.js'
4+
5+
/** @type {import('eslint-doc-generator').GenerateOptions} */
6+
const config = {
7+
postprocess: content =>
8+
format(content, { ...prettierRC, parser: 'markdown' }),
9+
}
10+
11+
export default config

.eslint-doc-generatorrc.mjs

-11
This file was deleted.

.eslintignore

-13
This file was deleted.

.eslintrc.js renamed to .eslintrc.cjs

+42-31
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
// ! This file is here for testing `no-unused-modules` rule for eslintrc
2+
13
const { version } = require('eslint/package.json')
24

3-
const nonLatestEslint = +version.split('.')[0] < 9
5+
const noEslintrc = +version.split('.')[0] > 8
6+
7+
const testCompiled = process.env.TEST_COMPILED === '1'
48

59
/**
610
* @type {import('eslint').Linter.Config}
@@ -12,15 +16,15 @@ module.exports = {
1216
'eslint:recommended',
1317
'plugin:@typescript-eslint/recommended',
1418
'plugin:eslint-plugin/recommended',
15-
'plugin:import-x/recommended',
19+
testCompiled && 'plugin:import-x/recommended',
1620
'plugin:json/recommended-legacy',
1721
'plugin:mdx/recommended',
1822
'plugin:n/recommended',
19-
'plugin:unicorn/recommended',
23+
!noEslintrc && 'plugin:unicorn/recommended',
2024
'plugin:yml/standard',
2125
'plugin:yml/prettier',
2226
'plugin:prettier/recommended',
23-
],
27+
].filter(Boolean),
2428
env: {
2529
node: true,
2630
es6: true,
@@ -34,7 +38,7 @@ module.exports = {
3438
'@typescript-eslint/no-non-null-assertion': 'off',
3539
'@typescript-eslint/no-require-imports': 'off',
3640

37-
'no-constant-condition': nonLatestEslint ? 'off' : 'error',
41+
'no-constant-condition': noEslintrc ? 'error' : 'off',
3842

3943
'eslint-plugin/consistent-output': ['error', 'always'],
4044
'eslint-plugin/meta-property-ordering': 'error',
@@ -52,31 +56,36 @@ module.exports = {
5256
'n/no-missing-import': 'off',
5357
'n/no-missing-require': 'off',
5458
'n/no-unsupported-features/es-syntax': 'off',
55-
'unicorn/filename-case': [
56-
'error',
57-
{
58-
case: 'kebabCase',
59-
ignore: [String.raw`^(CONTRIBUTING|README)\.md$`],
60-
},
61-
],
59+
...(noEslintrc || {
60+
'unicorn/filename-case': [
61+
'error',
62+
{
63+
case: 'kebabCase',
64+
ignore: [String.raw`^(CONTRIBUTING|README)\.md$`],
65+
},
66+
],
67+
}),
6268
'unicorn/no-array-callback-reference': 'off',
6369
'unicorn/no-array-reduce': 'off',
6470
'unicorn/no-null': 'off',
6571
'unicorn/prefer-module': 'off',
6672
'unicorn/prevent-abbreviations': 'off',
6773
'unicorn/prefer-at': 'off',
74+
'unicorn/prefer-export-from': ['error', { ignoreUsedVariables: true }],
6875

6976
// dog fooding
70-
'import-x/no-extraneous-dependencies': [
71-
'error',
72-
{
73-
devDependencies: ['test/**'],
74-
optionalDependencies: false,
75-
peerDependencies: true,
76-
bundledDependencies: false,
77-
},
78-
],
79-
'import-x/unambiguous': 'off',
77+
...(testCompiled && {
78+
'import-x/no-extraneous-dependencies': [
79+
'error',
80+
{
81+
devDependencies: ['test/**'],
82+
optionalDependencies: false,
83+
peerDependencies: true,
84+
bundledDependencies: false,
85+
},
86+
],
87+
'import-x/unambiguous': 'off',
88+
}),
8089
},
8190

8291
overrides: [
@@ -104,16 +113,18 @@ module.exports = {
104113
varsIgnorePattern: '^_',
105114
},
106115
],
107-
'import-x/consistent-type-specifier-style': 'error',
108-
'import-x/order': [
109-
'error',
110-
{
111-
alphabetize: {
112-
order: 'asc',
116+
...(testCompiled && {
117+
'import-x/consistent-type-specifier-style': 'error',
118+
'import-x/order': [
119+
'error',
120+
{
121+
alphabetize: {
122+
order: 'asc',
123+
},
124+
'newlines-between': 'always',
113125
},
114-
'newlines-between': 'always',
115-
},
116-
],
126+
],
127+
}),
117128
},
118129
settings: {
119130
'import-x/resolver': {

.github/workflows/ci.yml

+6-8
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ jobs:
2222
- 20
2323
- 22
2424
eslint:
25-
- '8.56'
26-
- '8'
27-
- '9'
25+
- 8.56
26+
- 8
27+
- 9
2828

2929
include:
3030
- executeLint: true
@@ -44,22 +44,20 @@ jobs:
4444
cache: yarn
4545

4646
- name: Install ESLint ${{ matrix.eslint }}
47+
if: ${{ matrix.eslint != 9 }}
4748
run: |
48-
yarn add -D eslint@${{ matrix.eslint }}
49+
yarn add -D eslint@${{ matrix.eslint }} eslint-plugin-unicorn@56
4950
5051
- name: Install Dependencies
5152
run: yarn --immutable
5253

5354
- name: Build and Test
54-
run: |
55-
yarn test-compiled
56-
yarn test
55+
run: yarn run-s test-compiled test
5756

5857
- name: Lint
5958
run: yarn lint
6059
if: ${{ matrix.executeLint }}
6160
env:
62-
EFF_NO_LINK_RULES: true
6361
PARSER_NO_WATCH: true
6462

6563
- name: Codecov

.github/workflows/codeql.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
name: CodeQL
22

33
on:
4-
push:
5-
pull_request:
4+
push: null
5+
pull_request: null
66
schedule:
77
- cron: '41 19 * * 6'
88

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

eslint.config.js

+179
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
// @ts-check
2+
3+
import { cjsRequire } from '@pkgr/core'
4+
import { config, configs } from 'typescript-eslint'
5+
import js from '@eslint/js'
6+
import eslintPlugin from 'eslint-plugin-eslint-plugin'
7+
import { flatConfigs } from 'eslint-plugin-import-x'
8+
import json from 'eslint-plugin-json'
9+
import * as mdx from 'eslint-plugin-mdx'
10+
import n from 'eslint-plugin-n'
11+
import unicorn from 'eslint-plugin-unicorn'
12+
import yml from 'eslint-plugin-yml'
13+
import prettier from 'eslint-plugin-prettier/recommended'
14+
import { createTypeScriptImportResolver } from 'eslint-import-resolver-typescript'
15+
import globals from 'globals'
16+
17+
const { version } = cjsRequire('eslint/package.json')
18+
19+
const noEslintrc = +version.split('.')[0] > 8
20+
21+
export default config(
22+
{
23+
ignores: [
24+
'.yarn',
25+
'lib',
26+
'coverage',
27+
'test/fixtures',
28+
'CHANGELOG.md',
29+
'!.*.js',
30+
],
31+
},
32+
js.configs.recommended,
33+
configs.recommended,
34+
flatConfigs.recommended,
35+
flatConfigs.typescript,
36+
json.configs.recommended,
37+
mdx.configs.flat,
38+
mdx.configs.flatCodeBlocks,
39+
n.configs['flat/recommended'],
40+
unicorn.configs['flat/recommended'],
41+
yml.configs['flat/standard'],
42+
yml.configs['flat/prettier'],
43+
prettier,
44+
{
45+
plugins: {
46+
'eslint-plugin': eslintPlugin,
47+
},
48+
settings: {
49+
'import-x/resolver-next': [
50+
createTypeScriptImportResolver({
51+
project: 'tsconfig.base.json',
52+
}),
53+
],
54+
},
55+
languageOptions: {
56+
parserOptions: {
57+
sourceType: 'module',
58+
ecmaVersion: 2020,
59+
},
60+
},
61+
rules: {
62+
'@typescript-eslint/no-non-null-assertion': 'off',
63+
'@typescript-eslint/no-require-imports': 'off',
64+
65+
'no-constant-condition': noEslintrc ? 'error' : 'off',
66+
67+
'eslint-plugin/consistent-output': ['error', 'always'],
68+
'eslint-plugin/meta-property-ordering': 'error',
69+
'eslint-plugin/no-deprecated-context-methods': 'error',
70+
'eslint-plugin/no-deprecated-report-api': 'off',
71+
'eslint-plugin/prefer-replace-text': 'error',
72+
'eslint-plugin/report-message-format': 'error',
73+
'eslint-plugin/require-meta-docs-description': [
74+
'error',
75+
{ pattern: String.raw`^(Enforce|Ensure|Prefer|Forbid).+\.$` },
76+
],
77+
'eslint-plugin/require-meta-schema': 'error',
78+
'eslint-plugin/require-meta-type': 'error',
79+
'n/no-extraneous-require': 'off',
80+
'n/no-missing-import': 'off',
81+
'n/no-missing-require': 'off',
82+
'n/no-unsupported-features/es-syntax': 'off',
83+
'unicorn/filename-case': [
84+
'error',
85+
{
86+
case: 'kebabCase',
87+
ignore: [String.raw`^(CONTRIBUTING|README)\.md$`],
88+
},
89+
],
90+
'unicorn/no-array-callback-reference': 'off',
91+
'unicorn/no-array-reduce': 'off',
92+
'unicorn/no-null': 'off',
93+
'unicorn/prefer-module': 'off',
94+
'unicorn/prevent-abbreviations': 'off',
95+
'unicorn/prefer-at': 'off',
96+
'unicorn/prefer-export-from': ['error', { ignoreUsedVariables: true }],
97+
98+
// dog fooding
99+
'import-x/no-extraneous-dependencies': [
100+
'error',
101+
{
102+
devDependencies: ['test/**'],
103+
optionalDependencies: false,
104+
peerDependencies: true,
105+
bundledDependencies: false,
106+
},
107+
],
108+
'import-x/unambiguous': 'off',
109+
},
110+
},
111+
{
112+
files: ['**/*.ts'],
113+
rules: {
114+
'@typescript-eslint/array-type': [
115+
2,
116+
{
117+
default: 'array-simple',
118+
},
119+
],
120+
'@typescript-eslint/consistent-type-definitions': 'error',
121+
'@typescript-eslint/consistent-type-imports': [
122+
'error',
123+
{
124+
fixStyle: 'inline-type-imports',
125+
},
126+
],
127+
'@typescript-eslint/no-unused-vars': [
128+
'error',
129+
{
130+
argsIgnorePattern: '^_',
131+
varsIgnorePattern: '^_',
132+
},
133+
],
134+
'import-x/consistent-type-specifier-style': 'error',
135+
'import-x/order': [
136+
'error',
137+
{
138+
alphabetize: {
139+
order: 'asc',
140+
},
141+
'newlines-between': 'always',
142+
},
143+
],
144+
},
145+
},
146+
{
147+
files: [
148+
'test/**/*',
149+
'.*.js',
150+
'**/*.d.ts',
151+
'**/.eslintrc.js',
152+
'eslint.config.js',
153+
'jest.config.ts',
154+
],
155+
rules: {
156+
'import-x/no-extraneous-dependencies': 'off',
157+
'n/no-extraneous-import': 'off',
158+
},
159+
},
160+
{
161+
files: ['**/*.{cjs,cts}'],
162+
languageOptions: {
163+
globals: globals.node,
164+
},
165+
},
166+
{
167+
files: ['global.d.ts'],
168+
rules: {
169+
'import-x/no-extraneous-dependencies': 'off',
170+
},
171+
},
172+
{
173+
files: ['README.md'],
174+
rules: {
175+
// https://github.com/bmish/eslint-doc-generator/issues/655
176+
'no-irregular-whitespace': 'off',
177+
},
178+
},
179+
)

0 commit comments

Comments
 (0)