Skip to content

Commit

Permalink
fix: migrate to ESLint 9
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesIves committed Apr 17, 2024
1 parent ea27152 commit 9c1917a
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 51 deletions.
4 changes: 2 additions & 2 deletions __tests__/execute.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('execute', () => {
stdout('hello')
await execute('echo Montezuma', './', true)

expect(exec).toBeCalledWith('echo Montezuma', [], {
expect(exec).toHaveBeenCalledWith('echo Montezuma', [], {
cwd: './',
silent: true,
ignoreReturnCode: false,
Expand All @@ -27,7 +27,7 @@ describe('execute', () => {
stdout('hello')
await execute('echo Montezuma', './', false)

expect(exec).toBeCalledWith('echo Montezuma', [], {
expect(exec).toHaveBeenCalledWith('echo Montezuma', [], {
cwd: './',
silent: false,
ignoreReturnCode: false,
Expand Down
54 changes: 27 additions & 27 deletions __tests__/git.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe('git', () => {
})

await init(action)
expect(execute).toBeCalledTimes(7)
expect(execute).toHaveBeenCalledTimes(7)
})

it('should catch when a function throws an error', async () => {
Expand Down Expand Up @@ -101,7 +101,7 @@ describe('git', () => {
})

await init(action)
expect(execute).toBeCalledTimes(7)
expect(execute).toHaveBeenCalledTimes(7)
})

it('should not unset git config if a user is using ssh', async () => {
Expand All @@ -123,7 +123,7 @@ describe('git', () => {
})

await init(action)
expect(execute).toBeCalledTimes(6)
expect(execute).toHaveBeenCalledTimes(6)

process.env.CI = undefined
})
Expand All @@ -144,7 +144,7 @@ describe('git', () => {
})

await init(action)
expect(execute).toBeCalledTimes(7)
expect(execute).toHaveBeenCalledTimes(7)
})
})

Expand All @@ -167,8 +167,8 @@ describe('git', () => {
const response = await deploy(action)

// Includes the call to generateWorktree
expect(execute).toBeCalledTimes(14)
expect(rmRF).toBeCalledTimes(1)
expect(execute).toHaveBeenCalledTimes(14)
expect(rmRF).toHaveBeenCalledTimes(1)
expect(response).toBe(Status.SUCCESS)
})

Expand All @@ -190,8 +190,8 @@ describe('git', () => {
const response = await deploy(action)

// Includes the call to generateWorktree
expect(execute).toBeCalledTimes(13)
expect(rmRF).toBeCalledTimes(1)
expect(execute).toHaveBeenCalledTimes(13)
expect(rmRF).toHaveBeenCalledTimes(1)
expect(response).toBe(Status.SUCCESS)
})

Expand All @@ -215,8 +215,8 @@ describe('git', () => {
await deploy(action)

// Includes the call to generateWorktree
expect(execute).toBeCalledTimes(14)
expect(rmRF).toBeCalledTimes(1)
expect(execute).toHaveBeenCalledTimes(14)
expect(rmRF).toHaveBeenCalledTimes(1)
})

it('should execute commands with single commit toggled and existing branch', async () => {
Expand All @@ -239,8 +239,8 @@ describe('git', () => {
await deploy(action)

// Includes the call to generateWorktree
expect(execute).toBeCalledTimes(13)
expect(rmRF).toBeCalledTimes(1)
expect(execute).toHaveBeenCalledTimes(13)
expect(rmRF).toHaveBeenCalledTimes(1)
})

it('should execute commands with single commit and dryRun toggled', async () => {
Expand All @@ -264,8 +264,8 @@ describe('git', () => {
await deploy(action)

// Includes the call to generateWorktree
expect(execute).toBeCalledTimes(13)
expect(rmRF).toBeCalledTimes(1)
expect(execute).toHaveBeenCalledTimes(13)
expect(rmRF).toHaveBeenCalledTimes(1)
})

it('should not ignore CNAME or nojekyll if they exist in the deployment folder', async () => {
Expand Down Expand Up @@ -295,9 +295,9 @@ describe('git', () => {
const response = await deploy(action)

// Includes the call to generateWorktree
expect(execute).toBeCalledTimes(14)
expect(rmRF).toBeCalledTimes(1)
expect(fs.existsSync).toBeCalledTimes(2)
expect(execute).toHaveBeenCalledTimes(14)
expect(rmRF).toHaveBeenCalledTimes(1)
expect(fs.existsSync).toHaveBeenCalledTimes(2)
expect(response).toBe(Status.SUCCESS)
})

Expand Down Expand Up @@ -327,8 +327,8 @@ describe('git', () => {
await deploy(action)

// Includes the call to generateWorktree
expect(execute).toBeCalledTimes(11)
expect(rmRF).toBeCalledTimes(1)
expect(execute).toHaveBeenCalledTimes(11)
expect(rmRF).toHaveBeenCalledTimes(1)
})
})

Expand All @@ -352,8 +352,8 @@ describe('git', () => {
await deploy(action)

// Includes the call to generateWorktree
expect(execute).toBeCalledTimes(11)
expect(rmRF).toBeCalledTimes(1)
expect(execute).toHaveBeenCalledTimes(11)
expect(rmRF).toHaveBeenCalledTimes(1)
})

it('should gracefully handle target folder', async () => {
Expand All @@ -372,9 +372,9 @@ describe('git', () => {

await deploy(action)

expect(execute).toBeCalledTimes(11)
expect(rmRF).toBeCalledTimes(1)
expect(mkdirP).toBeCalledTimes(1)
expect(execute).toHaveBeenCalledTimes(11)
expect(rmRF).toHaveBeenCalledTimes(1)
expect(mkdirP).toHaveBeenCalledTimes(1)
})

it('should stop early if there is nothing to commit', async () => {
Expand All @@ -392,8 +392,8 @@ describe('git', () => {
})

const response = await deploy(action)
expect(execute).toBeCalledTimes(11)
expect(rmRF).toBeCalledTimes(1)
expect(execute).toHaveBeenCalledTimes(11)
expect(rmRF).toHaveBeenCalledTimes(1)
expect(response).toBe(Status.SKIPPED)
})

Expand Down Expand Up @@ -466,7 +466,7 @@ describe('git', () => {
})

const response = await deploy(action)
expect(execute).toBeCalledTimes(16)
expect(execute).toHaveBeenCalledTimes(16)
expect(response).toBe(Status.SUCCESS)
})
})
Expand Down
18 changes: 9 additions & 9 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ describe('main', () => {
debug: true
})
await run(action)
expect(execute).toBeCalledTimes(18)
expect(rmRF).toBeCalledTimes(1)
expect(exportVariable).toBeCalledTimes(1)
expect(execute).toHaveBeenCalledTimes(18)
expect(rmRF).toHaveBeenCalledTimes(1)
expect(exportVariable).toHaveBeenCalledTimes(1)
})

it('should run through the commands and succeed', async () => {
Expand All @@ -73,9 +73,9 @@ describe('main', () => {
isTest: TestFlag.HAS_CHANGED_FILES
})
await run(action)
expect(execute).toBeCalledTimes(21)
expect(rmRF).toBeCalledTimes(1)
expect(exportVariable).toBeCalledTimes(1)
expect(execute).toHaveBeenCalledTimes(21)
expect(rmRF).toHaveBeenCalledTimes(1)
expect(exportVariable).toHaveBeenCalledTimes(1)
})

it('should throw if an error is encountered', async () => {
Expand All @@ -92,8 +92,8 @@ describe('main', () => {
isTest: TestFlag.HAS_CHANGED_FILES
})
await run(action)
expect(execute).toBeCalledTimes(0)
expect(setFailed).toBeCalledTimes(1)
expect(exportVariable).toBeCalledTimes(1)
expect(execute).toHaveBeenCalledTimes(0)
expect(setFailed).toHaveBeenCalledTimes(1)
expect(exportVariable).toHaveBeenCalledTimes(1)
})
})
18 changes: 9 additions & 9 deletions __tests__/ssh.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ describe('configureSSH', () => {

await configureSSH(action)

expect(execute).toBeCalledTimes(0)
expect(mkdirP).toBeCalledTimes(0)
expect(appendFileSync).toBeCalledTimes(0)
expect(execute).toHaveBeenCalledTimes(0)
expect(mkdirP).toHaveBeenCalledTimes(0)
expect(appendFileSync).toHaveBeenCalledTimes(0)
})

it('should configure the ssh client if a key is defined', async () => {
Expand All @@ -82,9 +82,9 @@ describe('configureSSH', () => {

await configureSSH(action)

expect(execFileSync).toBeCalledTimes(1)
expect(exportVariable).toBeCalledTimes(2)
expect(execSync).toBeCalledTimes(3)
expect(execFileSync).toHaveBeenCalledTimes(1)
expect(exportVariable).toHaveBeenCalledTimes(2)
expect(execSync).toHaveBeenCalledTimes(3)
})

it('should not export variables if the return from ssh-agent is skewed', async () => {
Expand All @@ -107,9 +107,9 @@ describe('configureSSH', () => {

await configureSSH(action)

expect(execFileSync).toBeCalledTimes(1)
expect(exportVariable).toBeCalledTimes(0)
expect(execSync).toBeCalledTimes(3)
expect(execFileSync).toHaveBeenCalledTimes(1)
expect(exportVariable).toHaveBeenCalledTimes(0)
expect(execSync).toHaveBeenCalledTimes(3)
})

it('should throw if something errors', async () => {
Expand Down
4 changes: 2 additions & 2 deletions __tests__/worktree.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ describe('generateWorktree', () => {
'gh1'
])

expect(async () => {
return expect(async () => {
await execute(
'git log --format=%s',
path.join(workspace, 'worktree'),
Expand Down Expand Up @@ -208,7 +208,7 @@ describe('generateWorktree', () => {

expect(dirEntries).toEqual(['.git'])

expect(async () => {
return expect(async () => {
await execute(
'git log --format=%s',
path.join(workspace, 'worktree'),
Expand Down
72 changes: 72 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';
import eslintConfigPrettier from "eslint-config-prettier";
import jest from "eslint-plugin-jest";

export default tseslint.config(
eslintConfigPrettier,
jest.configs['flat/recommended'],
eslint.configs.recommended,
...tseslint.configs.recommended,
{
languageOptions: {
globals: {
process: true,
module: true,
}
},
rules: {
"jest/no-conditional-expect": "off",
"@typescript-eslint/ban-types": [
"error",
{
types: {
"Number": {
"message": "Use number instead",
"fixWith": "number"
},
"String": {
"message": "Use string instead",
"fixWith": "string"
},
"Boolean": {
"message": "Use boolean instead",
"fixWith": "boolean"
},
"Object": {
"message": "Use object instead",
"fixWith": "object"
},
"{}": {
"message": "Use object instead",
"fixWith": "object"
},
"Symbol": {
"message": "Use symbol instead",
"fixWith": "symbol"
}
}
}
],
"@typescript-eslint/array-type": ["error", {"default": "array"}],
"@typescript-eslint/explicit-module-boundary-types": "error",
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/explicit-function-return-type": "error",
"object-shorthand": ["error", "always"],
"prefer-destructuring": [
"error",
{
"array": false,
"object": true
},
{
"enforceForRenamedProperties": false
}
],
"no-console": ["error", {"allow": ["warn", "error"]}],
"no-alert": "error",
"no-debugger": "error"
}
}
);
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
"@actions/core": "1.10.1",
"@actions/exec": "1.1.1",
"@actions/github": "6.0.0",
"@actions/io": "1.1.3"
"@actions/io": "1.1.3",
"@eslint/js": "^9.0.0",
"typescript-eslint": "^7.7.0"
},
"devDependencies": {
"@types/jest": "29.5.12",
Expand Down
11 changes: 10 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@
minimatch "^3.1.2"
strip-json-comments "^3.1.1"

"@eslint/js@9.0.0":
"@eslint/js@9.0.0", "@eslint/js@^9.0.0":
version "9.0.0"
resolved "https://registry.yarnpkg.com/@eslint/js/-/js-9.0.0.tgz#1a9e4b4c96d8c7886e0110ed310a0135144a1691"
integrity sha512-RThY/MnKrhubF6+s1JflwUjPEsnCEmYCWwqa/aRISKWNXGZ9epUwft4bUMM35SdKF9xvBrLydAM1RDHd1Z//ZQ==
Expand Down Expand Up @@ -3332,6 +3332,15 @@ type-fest@^0.8.1:
version "0.8.1"
resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.8.1.tgz#09e249ebde851d3b1e48d27c105444667f17b83d"

typescript-eslint@^7.7.0:
version "7.7.0"
resolved "https://registry.yarnpkg.com/typescript-eslint/-/typescript-eslint-7.7.0.tgz#b755e350dad25bb1e5b3826d11daa973dc0970ac"
integrity sha512-wZZ+7mTQJCn4mGAvzdERtL4vwKGM/mF9cMSMeKUllz3Hgbd1Mdd5L60Q+nJmCio9RB4OyMMr0EX4Ry2Q7jiAyw==
dependencies:
"@typescript-eslint/eslint-plugin" "7.7.0"
"@typescript-eslint/parser" "7.7.0"
"@typescript-eslint/utils" "7.7.0"

typescript@5.4.5:
version "5.4.5"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.4.5.tgz#42ccef2c571fdbd0f6718b1d1f5e6e5ef006f611"
Expand Down

0 comments on commit 9c1917a

Please sign in to comment.