Skip to content

Commit

Permalink
ci: run more tests (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
JounQin authored Mar 18, 2024
1 parent 196b37b commit 843cf49
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 17 deletions.
5 changes: 5 additions & 0 deletions .changeset/tricky-spiders-happen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eslint-plugin-import-x": patch
---

fix: known compatibility issues
10 changes: 7 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const eslintPkg = require('eslint/package.json')
const semver = require('semver')

/**
* @type {import('eslint').Linter.Config}
*/
// eslint-disable-next-line unicorn/prefer-module
module.exports = {
root: true,
extends: [
Expand All @@ -10,9 +12,11 @@ module.exports = {
'plugin:eslint-plugin/recommended',
'plugin:import-x/recommended',
'plugin:n/recommended',
'plugin:unicorn/recommended',
semver.satisfies(eslintPkg.version, '>=8')
? 'plugin:unicorn/recommended'
: undefined,
'plugin:prettier/recommended',
],
].filter(Boolean),
env: {
node: true,
es6: true,
Expand Down
26 changes: 21 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,21 @@ on:

jobs:
ci:
name: Lint and Test with Node.js ${{ matrix.node }} on ${{ matrix.os }}
name: Lint and Test with Node.js ${{ matrix.node }} and ESLint ${{ matrix.eslint }} on ${{ matrix.os }}
strategy:
matrix:
os:
- macos-latest
- ubuntu-latest
# - windows-latest
node:
- 16
- 18
- 20
eslint:
- 7.2
- 7
- 8
runs-on: ${{ matrix.os }}
steps:
- name: Checkout Repo
Expand All @@ -31,20 +38,29 @@ jobs:
# https://github.com/actions/setup-node/issues/531#issuecomment-1819151412
SKIP_YARN_COREPACK_CHECK: 1

- name: Install ESLint ${{ matrix.eslint }}
run: |
yarn add -D --ignore-engines eslint@${{ matrix.eslint }}
- name: Install Dependencies
run: yarn --immutable
run: yarn --ignore-engines
env:
SKIP_YARN_COREPACK_CHECK: 1

- name: Build, Lint and Test
- name: Build and Test
run: |
yarn build
yarn lint
yarn test-compiled
yarn test
env:
SKIP_YARN_COREPACK_CHECK: 1

- name: Lint
run: yarn lint
env:
EFF_NO_LINK_RULES: true
PARSER_NO_WATCH: true
SKIP_YARN_COREPACK_CHECK: 1
if: ${{ matrix.node == 20 && matrix.eslint == 8 }}

- name: Codecov
uses: codecov/codecov-action@v3
17 changes: 15 additions & 2 deletions src/rules/exports-last.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@ import type { TSESTree } from '@typescript-eslint/utils'

import { createRule } from '../utils'

const findLastIndex = <T>(array: T[], predicate: (item: T) => boolean) => {
let i = array.length - 1
while (i >= 0) {
if (predicate(array[i])) {
return i
}
i--
}
return -1
}

function isNonExportStatement({ type }: TSESTree.Node) {
return (
type !== 'ExportDefaultDeclaration' &&
Expand All @@ -27,8 +38,10 @@ export = createRule({
create(context) {
return {
Program({ body }) {
const lastNonExportStatementIndex =
body.findLastIndex(isNonExportStatement)
const lastNonExportStatementIndex = findLastIndex(
body,
isNonExportStatement,
)

if (lastNonExportStatementIndex !== -1) {
for (const node of body.slice(0, lastNonExportStatementIndex)) {
Expand Down
14 changes: 11 additions & 3 deletions src/rules/no-unused-modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import path from 'node:path'

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

import type { FileExtension, RuleContext } from '../types'
import {
Expand All @@ -20,11 +19,20 @@ import {
} from '../utils'

function listFilesToProcess(src: string[], extensions: FileExtension[]) {
const e = new FileEnumerator({
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
let FileEnumerator: typeof import('eslint/use-at-your-own-risk').FileEnumerator

try {
;({ FileEnumerator } = require('eslint/use-at-your-own-risk'))
} catch {
;({ FileEnumerator } = require('eslint/lib/cli-engine/file-enumerator'))
}

const enumerator = new FileEnumerator({
extensions,
})

return Array.from(e.iterateFiles(src), ({ filePath, ignored }) => ({
return Array.from(enumerator.iterateFiles(src), ({ filePath, ignored }) => ({
ignored,
filename: filePath,
}))
Expand Down
19 changes: 15 additions & 4 deletions test/rules/no-unused-modules.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import fs from 'node:fs'

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

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

Expand Down Expand Up @@ -1525,8 +1523,21 @@ describe('parser ignores prefixes like BOM and hashbang', () => {
invalid: [],
})
})
describe('supports flat eslint', () => {
const flatRuleTester = new FlatRuleTester() as TSESLint.RuleTester

let FlatRuleTester: typeof TSESLint.RuleTester | undefined

try {
;({ FlatRuleTester } = require('eslint/use-at-your-own-risk'))
} catch {
//
}

;(FlatRuleTester ? describe : describe.skip)('supports flat eslint', () => {
if (typeof FlatRuleTester !== 'function') {
return
}

const flatRuleTester = new FlatRuleTester()
flatRuleTester.run('no-unused-modules', rule, {
valid: [
{
Expand Down
1 change: 1 addition & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "@1stg/tsconfig/node",
"compilerOptions": {
"lib": ["ES2022"],
"paths": {
"eslint-plugin-import-x": ["./src"],
"eslint-plugin-import-x/package.json": ["./package.json"],
Expand Down

0 comments on commit 843cf49

Please sign in to comment.