Skip to content

Commit

Permalink
Merge pull request #15 from AurorNZ/eslint_upgrade
Browse files Browse the repository at this point in the history
Eslint upgrade
  • Loading branch information
alex-auror authored Sep 11, 2024
2 parents f81aac8 + 09d0925 commit e597062
Show file tree
Hide file tree
Showing 14 changed files with 667 additions and 397 deletions.
3 changes: 0 additions & 3 deletions .eslintignore

This file was deleted.

52 changes: 0 additions & 52 deletions .eslintrc.json

This file was deleted.

19 changes: 9 additions & 10 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
{
"printWidth": 120,
"tabWidth": 2,
"useTabs": false,
"semi": false,
"singleQuote": true,
"trailingComma": "none",
"bracketSpacing": false,
"arrowParens": "avoid",
"parser": "typescript"
}
"printWidth": 120,
"tabWidth": 2,
"useTabs": false,
"semi": false,
"singleQuote": true,
"trailingComma": "none",
"bracketSpacing": false,
"arrowParens": "avoid"
}
4 changes: 2 additions & 2 deletions __tests__/filter.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {describe, expect, test} from 'vitest'

import {Filter} from '../src/filter'
import {File, ChangeStatus} from '../src/file'
import {Filter} from '../src/filter'

describe('yaml filter parsing tests', () => {
test('throws if yaml is not a dictionary', () => {
Expand All @@ -26,7 +26,7 @@ describe('matching tests', () => {
const yaml = `
src: "src/**/*.js"
`
let filter = new Filter(yaml)
const filter = new Filter(yaml)
const files = modified(['src/app/module/file.js'])
const match = filter.match(files)
expect(match.src).toEqual(files)
Expand Down
4 changes: 2 additions & 2 deletions __tests__/git.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {describe, expect, test} from 'vitest'

import * as git from '../src/git'
import {ChangeStatus} from '../src/file'
import * as git from '../src/git'

describe('parsing output of the git diff command', () => {
test('parseGitDiffOutput returns files with correct change status', async () => {
test('parseGitDiffOutput returns files with correct change status', () => {
const files = git.parseGitDiffOutput(
'A\u0000LICENSE\u0000' + 'M\u0000src/index.ts\u0000' + 'D\u0000src/main.ts\u0000'
)
Expand Down
98 changes: 98 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// @ts-check

import {fixupPluginRules} from '@eslint/compat'
import {FlatCompat} from '@eslint/eslintrc'
import jsEslint from '@eslint/js'
import eslintConfigPrettier from 'eslint-config-prettier'
import tsEslint from 'typescript-eslint'

const compat = new FlatCompat({
baseDirectory: import.meta.dirname,
recommendedConfig: jsEslint.configs.recommended,
allConfig: jsEslint.configs.all
})

/* eslint-disable @typescript-eslint/explicit-function-return-type */
/**
* @param {string} name the pugin name
* @param {string} alias the plugin alias
* @returns {import("eslint").ESLint.Plugin}
*/
function legacyPlugin(name, alias = name) {
const plugin = compat.plugins(name)[0]?.plugins?.[alias]

if (!plugin) {
throw new Error(`Unable to resolve plugin ${name} and/or alias ${alias}`)
}

return fixupPluginRules(plugin)
}
/* eslint-enable @typescript-eslint/explicit-function-return-type */

export default tsEslint.config(
jsEslint.configs.recommended,
...tsEslint.configs.strictTypeChecked,
...tsEslint.configs.stylisticTypeChecked,
{
languageOptions: {
parserOptions: {
projectService: {
allowDefaultProject: ['*.js', '*.mjs']
},
tsconfigRootDir: import.meta.dirname
}
}
},
{
ignores: ['coverage', 'dist', 'lib']
},
{
plugins: {
github: legacyPlugin('eslint-plugin-github', 'github'), // pending https://github.com/github/eslint-plugin-github/issues/513
import: legacyPlugin('eslint-plugin-import', 'import') // Needed for above
},
rules: {
'@typescript-eslint/await-thenable': 'warn',
'@typescript-eslint/explicit-function-return-type': 'warn',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-floating-promises': ['warn', {ignoreIIFE: true, ignoreVoid: false}],
'@typescript-eslint/no-shadow': 'error',
'@typescript-eslint/no-unused-vars': ['warn', {argsIgnorePattern: '^_'}],
'@typescript-eslint/restrict-template-expressions': [
'error',
{
allowNever: true,
allowNumber: true
}
],
'github/array-foreach': 'error',
'github/no-implicit-buggy-globals': 'error',
'github/no-then': 'error',
'github/no-dynamic-script-tag': 'error',
'import/no-extraneous-dependencies': [
'error',
{
devDependencies: true,
optionalDependencies: true,
peerDependencies: true
}
],
'import/order': ['warn', {'newlines-between': 'always', alphabetize: {order: 'asc'}}],
'no-console': ['warn']
}
},
{
files: ['**/*.test.ts'],
rules: {
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off'
}
},
{
files: ['**/*.js', '**/*.mjs'],
...tsEslint.configs.disableTypeChecked
},
eslintConfigPrettier
)
27 changes: 17 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
"description": "Execute your workflow steps only if relevant files are modified.",
"main": "lib/main.js",
"scripts": {
"build": "tsc",
"tscheck": "tsc --noEmit",
"build": "tsc -b tsconfig.build.json",
"tscheck": "tsc",
"format": "prettier --write **/*.ts",
"format-check": "prettier --check **/*.ts",
"lint": "eslint src/**/*.ts",
"lint": "eslint",
"pack": "ncc build -m",
"test": "vitest",
"all": "pnpm run build && pnpm run format && pnpm run lint && pnpm run pack && pnpm test"
"all": "pnpm run build && pnpm run tscheck && pnpm run lint && pnpm run format && pnpm run pack && pnpm test run"
},
"repository": {
"type": "git",
Expand All @@ -33,18 +33,25 @@
"micromatch": "^4.0.5"
},
"devDependencies": {
"@octokit/webhooks-types": "^7.3.1",
"@eslint/compat": "^1.1.1",
"@eslint/eslintrc": "^3.1.0",
"@eslint/js": "^9.10.0",
"@octokit/webhooks-types": "^7.5.1",
"@tsconfig/node20": "^20.1.2",
"@types/eslint__js": "^8.42.3",
"@types/js-yaml": "^4.0.9",
"@types/micromatch": "^4.0.2",
"@types/node": "^20.0.0",
"@typescript-eslint/eslint-plugin": "^6.20.0",
"@typescript-eslint/parser": "^6.20.0",
"@typescript-eslint/eslint-plugin": "^8.5.0",
"@typescript-eslint/parser": "^8.5.0",
"@vercel/ncc": "^0.38.1",
"eslint": "^8.56.0",
"eslint-plugin-github": "^4.10.1",
"prettier": "^3.2.4",
"eslint": "^9.10.0",
"eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-typescript": "^3.6.3",
"eslint-plugin-github": "^5.0.1",
"prettier": "^3.3.3",
"typescript": "^5.3.3",
"typescript-eslint": "^8.5.0",
"vitest": "^2.0.5"
},
"volta": {
Expand Down
Loading

0 comments on commit e597062

Please sign in to comment.