Skip to content

Commit b4cbcea

Browse files
authored
ci: setup eslint workflow (#231)
* ci: preliminary eslint configuration * chore: clean up unused ignore directives * ci: add lint workflow to ci * ci: fix monorepo tslint configuration * chore: resolve lint warning for no-unnecessary-type-assertion * chore: resolve prefer-const lint error * chore: run prettier lint * chore: remove typeroots to resolve node:path warnings * chore: rebuild per-file suppressions * chore: remove excessive suppressions
1 parent 47d29ec commit b4cbcea

36 files changed

+2998
-1578
lines changed

.eslintrc.js

Lines changed: 0 additions & 19 deletions
This file was deleted.

.github/workflows/lint.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Lint
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
types: [opened, synchronize, reopened]
9+
10+
jobs:
11+
lint:
12+
name: Lint
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0
18+
19+
- name: Node.js
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version: lts/*
23+
cache: 'npm'
24+
25+
- name: Install dependencies
26+
run: npm ci --no-audit
27+
28+
- name: Lint
29+
run: npm run lint

eslint.config.js

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
// @ts-check
2+
import * as path from 'node:path'
3+
import { fileURLToPath } from 'node:url'
4+
import { includeIgnoreFile } from '@eslint/compat'
5+
import eslint from '@eslint/js'
6+
import node from 'eslint-plugin-n'
7+
import prettier from 'eslint-config-prettier'
8+
import tseslint from 'typescript-eslint'
9+
import vitest from '@vitest/eslint-plugin'
10+
11+
import temporarySuppressions from './eslint_temporary_suppressions.js'
12+
13+
const __filename = fileURLToPath(import.meta.url)
14+
const __dirname = path.dirname(__filename)
15+
16+
export default tseslint.config(
17+
// Global rules and configuration
18+
includeIgnoreFile(path.resolve(__dirname, '.gitignore')),
19+
{
20+
linterOptions: {
21+
reportUnusedDisableDirectives: true,
22+
},
23+
},
24+
25+
// JavaScript-specific rules
26+
eslint.configs.recommended,
27+
28+
// Typescript-specific rules
29+
tseslint.configs.strictTypeChecked,
30+
tseslint.configs.stylisticTypeChecked,
31+
{
32+
languageOptions: {
33+
parserOptions: {
34+
project: ['./tsconfig.base.json', './packages/*/tsconfig.json'],
35+
tsconfigRootDir: __dirname,
36+
},
37+
},
38+
},
39+
40+
{
41+
files: ['**/*.?(c|m)js?(x)'],
42+
...tseslint.configs.disableTypeChecked,
43+
},
44+
node.configs['flat/recommended'],
45+
{
46+
rules: {
47+
'n/no-extraneous-import': 'off',
48+
'n/no-extraneous-require': 'off',
49+
'n/no-missing-import': 'off',
50+
'n/no-missing-require': 'off',
51+
'n/no-unpublished-import': 'off',
52+
'n/no-unpublished-require': 'off',
53+
},
54+
},
55+
56+
// Project-specific rules
57+
{
58+
files: ['**/*.?(c|m)ts?(x)'],
59+
rules: {
60+
// `interface` and `type` have different use cases, allow both
61+
'@typescript-eslint/consistent-type-definitions': 'off',
62+
63+
// Ignore underscore-prefixed unused variables (mirrors tsc behavior)
64+
'@typescript-eslint/no-unused-vars': [
65+
'error',
66+
{
67+
args: 'all',
68+
argsIgnorePattern: '^_',
69+
caughtErrors: 'all',
70+
caughtErrorsIgnorePattern: '^_',
71+
destructuredArrayIgnorePattern: '^_',
72+
ignoreRestSiblings: true,
73+
varsIgnorePattern: '^_',
74+
},
75+
],
76+
},
77+
},
78+
79+
// Tests
80+
{
81+
files: ['**/*.test.?(c|m)[jt]s?(x)'],
82+
plugins: { vitest },
83+
rules: {
84+
...vitest.configs.recommended.rules,
85+
86+
'vitest/expect-expect': [
87+
'error',
88+
{
89+
assertFunctionNames: [
90+
// Defaults
91+
'assert',
92+
'expect',
93+
94+
// Fix issue where text-context-specific `expect()` calls trigger false positive
95+
't.expect',
96+
'ctx.expect',
97+
'context.expect',
98+
99+
// Custom assertion functions
100+
'assertNetlifyToml',
101+
],
102+
},
103+
],
104+
},
105+
},
106+
107+
...temporarySuppressions,
108+
109+
// Must be last
110+
prettier,
111+
)

0 commit comments

Comments
 (0)