Skip to content

Commit 843cf49

Browse files
authored
ci: run more tests (#56)
1 parent 196b37b commit 843cf49

File tree

7 files changed

+75
-17
lines changed

7 files changed

+75
-17
lines changed

.changeset/tricky-spiders-happen.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-import-x": patch
3+
---
4+
5+
fix: known compatibility issues

.eslintrc.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
const eslintPkg = require('eslint/package.json')
2+
const semver = require('semver')
3+
14
/**
25
* @type {import('eslint').Linter.Config}
36
*/
4-
// eslint-disable-next-line unicorn/prefer-module
57
module.exports = {
68
root: true,
79
extends: [
@@ -10,9 +12,11 @@ module.exports = {
1012
'plugin:eslint-plugin/recommended',
1113
'plugin:import-x/recommended',
1214
'plugin:n/recommended',
13-
'plugin:unicorn/recommended',
15+
semver.satisfies(eslintPkg.version, '>=8')
16+
? 'plugin:unicorn/recommended'
17+
: undefined,
1418
'plugin:prettier/recommended',
15-
],
19+
].filter(Boolean),
1620
env: {
1721
node: true,
1822
es6: true,

.github/workflows/ci.yml

+21-5
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,21 @@ on:
66

77
jobs:
88
ci:
9-
name: Lint and Test with Node.js ${{ matrix.node }} on ${{ matrix.os }}
9+
name: Lint and Test with Node.js ${{ matrix.node }} and ESLint ${{ matrix.eslint }} on ${{ matrix.os }}
1010
strategy:
1111
matrix:
1212
os:
13+
- macos-latest
1314
- ubuntu-latest
15+
# - windows-latest
1416
node:
17+
- 16
1518
- 18
1619
- 20
20+
eslint:
21+
- 7.2
22+
- 7
23+
- 8
1724
runs-on: ${{ matrix.os }}
1825
steps:
1926
- name: Checkout Repo
@@ -31,20 +38,29 @@ jobs:
3138
# https://github.com/actions/setup-node/issues/531#issuecomment-1819151412
3239
SKIP_YARN_COREPACK_CHECK: 1
3340

41+
- name: Install ESLint ${{ matrix.eslint }}
42+
run: |
43+
yarn add -D --ignore-engines eslint@${{ matrix.eslint }}
44+
3445
- name: Install Dependencies
35-
run: yarn --immutable
46+
run: yarn --ignore-engines
3647
env:
3748
SKIP_YARN_COREPACK_CHECK: 1
3849

39-
- name: Build, Lint and Test
50+
- name: Build and Test
4051
run: |
41-
yarn build
42-
yarn lint
52+
yarn test-compiled
4353
yarn test
54+
env:
55+
SKIP_YARN_COREPACK_CHECK: 1
56+
57+
- name: Lint
58+
run: yarn lint
4459
env:
4560
EFF_NO_LINK_RULES: true
4661
PARSER_NO_WATCH: true
4762
SKIP_YARN_COREPACK_CHECK: 1
63+
if: ${{ matrix.node == 20 && matrix.eslint == 8 }}
4864

4965
- name: Codecov
5066
uses: codecov/codecov-action@v3

src/rules/exports-last.ts

+15-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@ import type { TSESTree } from '@typescript-eslint/utils'
22

33
import { createRule } from '../utils'
44

5+
const findLastIndex = <T>(array: T[], predicate: (item: T) => boolean) => {
6+
let i = array.length - 1
7+
while (i >= 0) {
8+
if (predicate(array[i])) {
9+
return i
10+
}
11+
i--
12+
}
13+
return -1
14+
}
15+
516
function isNonExportStatement({ type }: TSESTree.Node) {
617
return (
718
type !== 'ExportDefaultDeclaration' &&
@@ -27,8 +38,10 @@ export = createRule({
2738
create(context) {
2839
return {
2940
Program({ body }) {
30-
const lastNonExportStatementIndex =
31-
body.findLastIndex(isNonExportStatement)
41+
const lastNonExportStatementIndex = findLastIndex(
42+
body,
43+
isNonExportStatement,
44+
)
3245

3346
if (lastNonExportStatementIndex !== -1) {
3447
for (const node of body.slice(0, lastNonExportStatementIndex)) {

src/rules/no-unused-modules.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import path from 'node:path'
77

88
import { TSESTree } from '@typescript-eslint/utils'
9-
import { FileEnumerator } from 'eslint/use-at-your-own-risk'
109

1110
import type { FileExtension, RuleContext } from '../types'
1211
import {
@@ -20,11 +19,20 @@ import {
2019
} from '../utils'
2120

2221
function listFilesToProcess(src: string[], extensions: FileExtension[]) {
23-
const e = new FileEnumerator({
22+
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
23+
let FileEnumerator: typeof import('eslint/use-at-your-own-risk').FileEnumerator
24+
25+
try {
26+
;({ FileEnumerator } = require('eslint/use-at-your-own-risk'))
27+
} catch {
28+
;({ FileEnumerator } = require('eslint/lib/cli-engine/file-enumerator'))
29+
}
30+
31+
const enumerator = new FileEnumerator({
2432
extensions,
2533
})
2634

27-
return Array.from(e.iterateFiles(src), ({ filePath, ignored }) => ({
35+
return Array.from(enumerator.iterateFiles(src), ({ filePath, ignored }) => ({
2836
ignored,
2937
filename: filePath,
3038
}))

test/rules/no-unused-modules.spec.ts

+15-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import fs from 'node:fs'
22

33
import { TSESLint } from '@typescript-eslint/utils'
4-
// @ts-expect-error - no types yet
5-
import { FlatRuleTester } from 'eslint/use-at-your-own-risk'
64

75
import { test, testVersion, testFilePath, parsers } from '../utils'
86

@@ -1525,8 +1523,21 @@ describe('parser ignores prefixes like BOM and hashbang', () => {
15251523
invalid: [],
15261524
})
15271525
})
1528-
describe('supports flat eslint', () => {
1529-
const flatRuleTester = new FlatRuleTester() as TSESLint.RuleTester
1526+
1527+
let FlatRuleTester: typeof TSESLint.RuleTester | undefined
1528+
1529+
try {
1530+
;({ FlatRuleTester } = require('eslint/use-at-your-own-risk'))
1531+
} catch {
1532+
//
1533+
}
1534+
1535+
;(FlatRuleTester ? describe : describe.skip)('supports flat eslint', () => {
1536+
if (typeof FlatRuleTester !== 'function') {
1537+
return
1538+
}
1539+
1540+
const flatRuleTester = new FlatRuleTester()
15301541
flatRuleTester.run('no-unused-modules', rule, {
15311542
valid: [
15321543
{

tsconfig.base.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"extends": "@1stg/tsconfig/node",
33
"compilerOptions": {
4+
"lib": ["ES2022"],
45
"paths": {
56
"eslint-plugin-import-x": ["./src"],
67
"eslint-plugin-import-x/package.json": ["./package.json"],

0 commit comments

Comments
 (0)