ESLint: Migrate to flat config, isolate Prettier, fix errors (#120)

This commit is contained in:
Jens Ochsenmeier
2024-06-14 14:54:49 +02:00
committed by GitHub
parent ba3bb36eb2
commit a9af4756ad
23 changed files with 1797 additions and 3088 deletions
-28
View File
@@ -1,28 +0,0 @@
module.exports = {
ignorePatterns: ['dist/**/*', 'build/**/*'],
extends: ['standard', 'plugin:@typescript-eslint/recommended', 'plugin:prettier/recommended'],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: '2020'
},
plugins: ['@typescript-eslint', 'prettier'],
rules: {
'import/order': 'error',
'no-use-before-define': 'off',
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
'n/no-callback-literal': 'off',
'@typescript-eslint/consistent-type-imports': ['error', { prefer: 'type-imports' }],
'@typescript-eslint/no-use-before-define': 'error',
'prettier/prettier': [
'error',
{
tabWidth: 2,
printWidth: 120,
singleQuote: true,
trailingComma: 'none',
semi: false
}
]
}
}
+2 -2
View File
@@ -7,7 +7,7 @@ updates:
groups:
dependencies:
patterns:
- "*"
- '*'
- package-ecosystem: npm
directory: /
schedule:
@@ -15,4 +15,4 @@ updates:
groups:
dependencies:
patterns:
- "*"
- '*'
+1 -1
View File
@@ -23,4 +23,4 @@ changelog:
- dependencies
- title: 🤷🏻 Other changes
labels:
- "*"
- '*'
+14 -14
View File
@@ -216,25 +216,25 @@ jobs:
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Move pixi.toml
run: mv test/default/* .
- uses: ./
with:
cache: false
pixi-bin-path: custom-bin/pixi${{ matrix.os == 'windows-latest' && '.exe' || '' }}
- run: |
test -f custom-bin/pixi${{ matrix.os == 'windows-latest' && '.exe' || '' }}
pixi --help
which pixi | grep -q custom-bin/pixi
# which pixi should be absolute
which pixi | grep -q "^/"
- uses: actions/checkout@v4
- name: Move pixi.toml
run: mv test/default/* .
- uses: ./
with:
cache: false
pixi-bin-path: custom-bin/pixi${{ matrix.os == 'windows-latest' && '.exe' || '' }}
- run: |
test -f custom-bin/pixi${{ matrix.os == 'windows-latest' && '.exe' || '' }}
pixi --help
which pixi | grep -q custom-bin/pixi
# which pixi should be absolute
which pixi | grep -q "^/"
existing-pixi-bin:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
ignore-reason: [ none, version, version-latest, url, bin-path]
ignore-reason: [none, version, version-latest, url, bin-path]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
+3
View File
@@ -100,3 +100,6 @@ lib/**/*
# Ignore jetbrains files
.idea
# ESBuild metafile
metafile*.json
+1
View File
@@ -0,0 +1 @@
dist
+3
View File
@@ -0,0 +1,3 @@
{
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
+8 -7
View File
@@ -25,7 +25,7 @@ GitHub Action to set up the [pixi](https://github.com/prefix-dev/pixi) package m
```yml
- uses: prefix-dev/setup-pixi@v0.8.1
with:
pixi-version: v0.23.0
pixi-version: v0.24.1
cache: true
auth-host: prefix.dev
auth-token: ${{ secrets.PREFIX_DEV_TOKEN }}
@@ -49,7 +49,7 @@ GitHub Action to set up the [pixi](https://github.com/prefix-dev/pixi) package m
> groups:
> dependencies:
> patterns:
> - "*"
> - '*'
> ```
## Features
@@ -117,10 +117,10 @@ test:
matrix:
environment: [py311, py312]
steps:
- uses: actions/checkout@v4
- uses: prefix-dev/setup-pixi@v0.8.1
with:
environments: ${{ matrix.environment }}
- uses: actions/checkout@v4
- uses: prefix-dev/setup-pixi@v0.8.1
with:
environments: ${{ matrix.environment }}
```
#### Install multiple environments in one job
@@ -216,6 +216,7 @@ You can even run Python scripts like this:
```
If you want to use PowerShell, you need to specify `-Command` as well.
```yml
- run: | # everything here will be run inside of the pixi environment
python --version | Select-String "3.11"
@@ -352,5 +353,5 @@ If you want to see more examples, you can take a look at the [GitHub Workflows o
1. Clone this repository.
2. Run `pnpm install` inside the repository (if you don't have [`pnpm`](https://github.com/pnpm/pnpm) installed, you can install it with `pixi global install pnpm`).
3. Run `pnpm dev` for live transpilation of the TypeScript source code.
3. Run `pnpm dev` for live transpilation of the TypeScript source code.
4. To test the action, you can run [`act`](https://github.com/nektos/act) (inside docker) or use :sparkles: CI driven development :sparkles:.
+1 -2
View File
@@ -27,8 +27,7 @@ inputs:
`$GITHUB_PATH`. If more than one environment is specified in `environments`, this must be the name of the
environment. Defaults to `false`. Requires at least pixi v0.21.0.
locked:
description:
Whether to use `pixi install --locked`. Defaults to `true` when the lockfile is present, otherwise `false`.
description: Whether to use `pixi install --locked`. Defaults to `true` when the lockfile is present, otherwise `false`.
frozen:
description: Whether to use `pixi install --frozen`. Defaults to `false`.
cache:
Generated Vendored
+477 -867
View File
File diff suppressed because it is too large Load Diff
Generated Vendored
+172 -311
View File
File diff suppressed because it is too large Load Diff
+37
View File
@@ -0,0 +1,37 @@
// @ts-check
import eslint from '@eslint/js'
import tseslint from 'typescript-eslint'
export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.strictTypeChecked,
...tseslint.configs.stylisticTypeChecked,
{
ignores: ['dist/*']
},
{
languageOptions: {
parserOptions: {
project: true,
tsconfigRootDir: import.meta.dirname
}
}
},
{
rules: {
'@typescript-eslint/no-unused-vars': [
'error',
{
argsIgnorePattern: '^_'
}
],
'@typescript-eslint/prefer-nullish-coalescing': [
'error',
{
ignoreConditionalTests: true
}
]
}
}
)
+13 -17
View File
@@ -6,8 +6,9 @@
"scripts": {
"build": "tsup",
"dev": "tsup --watch",
"lint": "eslint ./src --ext ts",
"lint:fix": "eslint ./src --ext ts --fix"
"eslint": "eslint .",
"lint": "pnpm eslint && prettier -c .",
"lint:fix": "eslint . --fix && prettier -w ."
},
"repository": {
"type": "git",
@@ -29,22 +30,17 @@
"@iarna/toml": "^2.2.5",
"untildify": "^5.0.0",
"which": "^4.0.0",
"zod": "^3.22.4"
"zod": "^3.23.8"
},
"devDependencies": {
"@types/node": "^20.12.2",
"@types/which": "^3.0.3",
"@typescript-eslint/eslint-plugin": "^7.4.0",
"@typescript-eslint/parser": "^7.4.0",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-config-standard": "^17.1.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-n": "^16.6.2",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-promise": "^6.1.1",
"prettier": "^3.2.5",
"tsup": "^8.0.2",
"typescript": "^5.4.3"
"@eslint/js": "^9.4.0",
"@types/eslint__js": "^8.42.3",
"@types/node": "^20.14.2",
"@types/which": "^3.0.4",
"eslint": "^9.4.0",
"prettier": "^3.3.2",
"tsup": "^8.1.0",
"typescript": "^5.4.5",
"typescript-eslint": "^7.13.0"
}
}
+998 -1795
View File
File diff suppressed because it is too large Load Diff
+9
View File
@@ -0,0 +1,9 @@
const config = {
tabWidth: 2,
printWidth: 120,
singleQuote: true,
trailingComma: 'none',
semi: false
}
export default config
+5 -4
View File
@@ -1,9 +1,9 @@
import * as os from 'os'
import os from 'os'
import * as osPath from 'path'
import * as core from '@actions/core'
import { executeGetOutput, pixiCmd } from './util'
type ShellHook = {
interface ShellHook {
environment_variables: Record<string, string>
}
@@ -11,9 +11,10 @@ const splitEnvironment = (shellHook: ShellHook): [Record<string, string>, string
if (os.platform() === 'win32') {
// On Windows, environment variables are case-insensitive but JSON isn't...
const pathEnvs = Object.keys(shellHook.environment_variables).filter((k) => k.toUpperCase() === 'PATH')
if (pathEnvs) {
if (pathEnvs.length > 0) {
const caseSensitivePathName = pathEnvs[0]
const path = shellHook.environment_variables[caseSensitivePathName]
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
delete shellHook.environment_variables[caseSensitivePathName]
return [shellHook.environment_variables, path]
}
@@ -47,7 +48,7 @@ export const activateEnvironment = async (environment: string): Promise<void> =>
// First, obtain the environment variables that would be set by environment activation
const envOption = environment === 'default' ? '' : `-e ${environment}`
const shellHookOutput = await executeGetOutput(pixiCmd(`shell-hook ${envOption} --json`), { silent: true })
const shellHook: ShellHook = JSON.parse(shellHookOutput.stdout)
const shellHook = JSON.parse(shellHookOutput.stdout) as ShellHook
// Then, we split the environment variables into the special 'PATH' and all others
const [envVars, path] = splitEnvironment(shellHook)
+7 -5
View File
@@ -25,7 +25,8 @@ export const generateCacheKey = async (cacheKeyPrefix: string) =>
core.debug(`sha: ${sha}`)
return `${cacheKeyPrefix}${getCondaArch()}-${sha}`
})
.catch((err) => {
.catch((err: unknown) => {
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
throw new Error(`Failed to generate cache key: ${err}`)
})
@@ -58,7 +59,7 @@ export const tryRestoreCache = (): Promise<string | undefined> => {
export const saveCache = () => {
const cache_ = options.cache
if (!cache_ || !cache_.cacheWrite) {
if (!cache_?.cacheWrite) {
core.debug('Skipping pixi cache save.')
return Promise.resolve(undefined)
}
@@ -71,10 +72,11 @@ export const saveCache = () => {
cache
.saveCache([cachePath], cacheKey, undefined, false)
.then((cacheId) => {
core.info(`Saved cache with ID \`${cacheId}\``)
core.info(`Saved cache with ID "${cacheId.toString()}"`)
})
.catch((err) => {
core.error(`Error saving cache: ${err.message}`)
.catch((err: unknown) => {
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
core.error(`Error saving cache: ${err}`)
})
)
)
+7 -5
View File
@@ -19,7 +19,9 @@ const downloadPixi = (source: PixiSource) => {
.mkdir(path.dirname(options.pixiBinPath), { recursive: true })
.then(() => downloadTool(url, options.pixiBinPath))
.then((_downloadPath) => fs.chmod(options.pixiBinPath, 0o755))
.then(() => core.info(`Pixi installed to ${options.pixiBinPath}`))
.then(() => {
core.info(`Pixi installed to ${options.pixiBinPath}`)
})
})
}
@@ -29,7 +31,7 @@ const pixiLogin = () => {
core.debug('Skipping pixi login.')
return Promise.resolve(0)
}
core.debug(`auth keys: ${Object.keys(auth)}`)
core.debug(`auth keys: ${Object.keys(auth).toString()}`)
return core.group('Logging in to private channel', () => {
// tokens get censored in the logs as long as they are a github secret
if ('token' in auth) {
@@ -114,7 +116,7 @@ const generateInfo = () => core.group('pixi info', () => execute(pixiCmd('info')
const activateEnv = (environment: string) => core.group('Activate environment', () => activateEnvironment(environment))
const run = async () => {
core.debug(`process.env.HOME: ${process.env.HOME}`)
core.debug(`process.env.HOME: ${process.env.HOME ?? '-'}`)
core.debug(`os.homedir(): ${os.homedir()}`)
if (options.downloadPixi) {
await downloadPixi(options.pixiSource)
@@ -130,7 +132,8 @@ const run = async () => {
}
run()
.catch((error) => {
.then(() => exit(0)) // workaround for https://github.com/actions/toolkit/issues/1578
.catch((error: unknown) => {
if (core.isDebug()) {
throw error
}
@@ -143,4 +146,3 @@ run()
}
throw error
})
.then(() => exit(0)) // workaround for https://github.com/actions/toolkit/issues/1578
+6 -6
View File
@@ -15,7 +15,7 @@ type Inputs = Readonly<{
manifestPath?: string
runInstall?: boolean
environments?: string[]
activateEnvironment?: boolean | string
activateEnvironment?: string
frozen?: boolean
locked?: boolean
cache?: boolean
@@ -53,7 +53,7 @@ type Auth = {
}
)
type Cache = {
interface Cache {
cacheKeyPrefix: string
cacheWrite: boolean
}
@@ -215,7 +215,7 @@ const inferOptions = (inputs: Inputs): Options => {
const parsedContent: Record<string, unknown> = parse(fileContent)
// Test if the tool.pixi table is present in the pyproject.toml file, if so, use it as the manifest file.
if (parsedContent?.tool && typeof parsedContent.tool === 'object' && 'pixi' in parsedContent.tool) {
if (parsedContent.tool && typeof parsedContent.tool === 'object' && 'pixi' in parsedContent.tool) {
core.debug(`The tool.pixi table found, using ${pyprojectPath} as manifest file.`)
manifestPath = pyprojectPath
}
@@ -230,7 +230,7 @@ const inferOptions = (inputs: Inputs): Options => {
const pixiLockFile = path.join(path.dirname(manifestPath), 'pixi.lock')
const lockFileAvailable = existsSync(pixiLockFile)
core.debug(`lockFileAvailable: ${lockFileAvailable}`)
core.debug(`lockFileAvailable: ${lockFileAvailable ? 'yes' : 'no'}`)
if (!lockFileAvailable && inputs.cacheWrite === true) {
throw new Error('You cannot specify cache-write = true without a lock file present')
}
@@ -265,8 +265,8 @@ const inferOptions = (inputs: Inputs): Options => {
}
: {
host: inputs.authHost,
username: inputs.authUsername!,
password: inputs.authPassword!
username: inputs.authUsername,
password: inputs.authPassword
}) as Auth)
const postCleanup = inputs.postCleanup ?? true
return {
+17 -14
View File
@@ -1,6 +1,6 @@
import fs from 'fs/promises'
import path from 'path'
import * as os from 'os'
import os from 'os'
import { exit } from 'process'
import * as core from '@actions/core'
import { options } from './options'
@@ -37,9 +37,10 @@ const cleanupEnv = () => {
return fs.rm(envDir, { recursive: true })
}
const determineCacheDir = () => {
const determineCacheDir = (): string => {
// rattler uses dirs::cache_dir https://docs.rs/dirs/latest/dirs/fn.cache_dir.html
if (os.platform() === 'win32') {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return process.env.LOCALAPPDATA!
}
if (os.platform() === 'linux') {
@@ -68,16 +69,18 @@ const run = () => {
return Promise.resolve()
}
run().catch((error) => {
if (core.isDebug()) {
run()
.then(() => exit(0)) // workaround for https://github.com/actions/toolkit/issues/1578
.catch((error: unknown) => {
if (core.isDebug()) {
throw error
}
if (error instanceof Error) {
core.setFailed(error.message)
exit(1)
} else if (typeof error === 'string') {
core.setFailed(error)
exit(1)
}
throw error
}
if (error instanceof Error) {
core.setFailed(error.message)
exit(1)
} else if (typeof error === 'string') {
core.setFailed(error)
exit(1)
}
throw error
})
})
+1 -1
View File
@@ -1,6 +1,6 @@
import type { BinaryLike } from 'crypto'
import { createHash } from 'crypto'
import * as os from 'os'
import os from 'os'
import * as core from '@actions/core'
import type { ExecOptions } from '@actions/exec'
import { exec, getExecOutput } from '@actions/exec'
+7 -7
View File
@@ -1,12 +1,12 @@
{
"compilerOptions": {
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"outDir": "./lib", /* Redirect output structure to the directory. */
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
"strict": true, /* Enable all strict type-checking options. */
"noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
"target": "ES2020" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */,
"module": "CommonJS" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
"outDir": "./lib" /* Redirect output structure to the directory. */,
"rootDir": "./src" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,
"strict": true /* Enable all strict type-checking options. */,
"noImplicitAny": true /* Raise error on expressions and declarations with an implied 'any' type. */,
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
},
"exclude": ["node_modules", "**/*.test.ts"]
}
+8 -2
View File
@@ -8,9 +8,15 @@ export default defineConfig({
dts: false,
clean: true,
target: 'es2020',
format: ['cjs'],
sourcemap: true,
format: 'cjs',
sourcemap: false,
platform: 'node',
minify: false,
outExtension() {
return {
js: '.js'
}
},
// need to bundle dependencies because they aren't available otherwise when run inside the action
noExternal: [
'@actions/core',