Skip to content

Commit 3cee6a0

Browse files
committed
chore: Switch from tslint to eslint
tslint is end-of-life, and warns when you install it. Additionally, the version we were on didn't support 'import type' expressions, as well as optional-chaining & null coalescing when I tried to use those in #1204 This PR does update a bunch of tslint-disable comments, but otherwise tries to minimally change runtime source in danger-js. If we want to tighten the eslint rules, I'd be super supportive, but I didn't want to cause a ton of thrash, so mostly the rules that are enabled are the ones that don't trigger on tons of existing code.
1 parent 1047571 commit 3cee6a0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+686
-137
lines changed

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
source/danger.d.ts
2+
source/runner/_tests/fixtures/*.ts

.eslintrc.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
module.exports = {
2+
env: {
3+
browser: true,
4+
es6: true,
5+
node: true,
6+
},
7+
extends: ["plugin:@typescript-eslint/recommended", "plugin:jest/recommended", "prettier"],
8+
parser: "@typescript-eslint/parser",
9+
parserOptions: {
10+
project: "tsconfig.spec.json",
11+
sourceType: "module",
12+
},
13+
plugins: ["eslint-plugin-jest", "eslint-plugin-jsdoc", "@typescript-eslint"],
14+
rules: {
15+
"@typescript-eslint/naming-convention": "error",
16+
"@typescript-eslint/no-empty-function": "error",
17+
"@typescript-eslint/no-unused-expressions": "error",
18+
19+
// Something is grumpy about these rules re: node imports - TODO
20+
"@typescript-eslint/no-require-imports": "off",
21+
"@typescript-eslint/no-var-requires": "off",
22+
23+
curly: "error",
24+
"jsdoc/check-alignment": "error",
25+
"jsdoc/check-indentation": "off",
26+
"jsdoc/newline-after-description": "off",
27+
"no-empty": "error",
28+
// This is used intentionally in a bunch of ci_source/providers
29+
"no-empty-function": "off",
30+
"no-redeclare": "error",
31+
"no-var": "error",
32+
// There are a bunch of existing uses of 'let' where this rule would trigger
33+
"prefer-const": "off",
34+
35+
// This project has a ton of interacting APIs, and sometimes it's helpful to be explicit, even if the type is trivial
36+
"@typescript-eslint/no-inferrable-types": "off",
37+
38+
"no-unused-expressions": "off",
39+
"@typescript-eslint/no-unused-expressions": "error",
40+
41+
"no-unused-vars": "off",
42+
"@typescript-eslint/no-unused-vars": [
43+
"warn",
44+
{
45+
// Allow function args to be unused
46+
args: "none",
47+
argsIgnorePattern: "^_",
48+
varsIgnorePattern: "^_",
49+
caughtErrorsIgnorePattern: "^_",
50+
},
51+
],
52+
53+
"jest/no-disabled-tests": "warn",
54+
"jest/no-focused-tests": "error",
55+
"jest/no-identical-title": "error",
56+
"jest/prefer-to-have-length": "off",
57+
"jest/valid-expect": "error",
58+
"@typescript-eslint/no-non-null-assertion": "off",
59+
// Tons of violations in the codebase
60+
"@typescript-eslint/naming-convention": "off",
61+
// Used liberally in the codebase
62+
"@typescript-eslint/no-explicit-any": "off",
63+
// This has value in communicating with other Developers even if it has no functional effect.
64+
"@typescript-eslint/no-empty-interface": "off",
65+
},
66+
}

.vscode/extensions.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"recommendations": [
33
"Orta.vscode-jest",
44
"esbenp.prettier-vscode",
5+
"dbaeumer.vscode-eslint",
56
"christian-kohler.path-intellisense",
67
"wayou.vscode-todo-highlight"
78
]

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
<!-- Your comment below this -->
1717

18+
- *Chore:* Switch from tslint to eslint (tslint is end-of-life) - [#1205](https://github.com/danger/danger-js/pull/1205) [@fbartho]
1819

1920
<!-- Your comment above this -->
2021

package.json

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"git add"
3535
],
3636
"*.@(ts|tsx)": [
37-
"tslint --fix",
37+
"eslint --fix",
3838
"yarn prettier --write",
3939
"git add"
4040
]
@@ -56,8 +56,8 @@
5656
"test:fixtures": "node ./scripts/run-fixtures.js",
5757
"test:update-fixtures": "yarn test:fixtures --update",
5858
"test:watch": "jest --watch",
59-
"lint": "tslint \"source/**/*.ts\"",
60-
"lint:fix": "tslint \"source/**/*.ts\" --fix",
59+
"lint": "eslint \"source/*.ts\" \"source/**/*.ts\"",
60+
"lint:fix": "yarn --silent lint --fix",
6161
"prepublishOnly": "yarn build && yarn jest && yarn declarations && yarn build:flow-types && yarn build:pretty-types",
6262
"build": "shx rm -rf ./distribution && tsc -p tsconfig.production.json && madge ./distribution --circular",
6363
"build:fast": "tsc -p tsconfig.production.json",
@@ -114,9 +114,15 @@
114114
"@types/prettier": "^1.16.1",
115115
"@types/readline-sync": "^1.4.3",
116116
"@types/voca": "^1.4.0",
117+
"@typescript-eslint/eslint-plugin": "^5.10.1",
118+
"@typescript-eslint/parser": "^5.10.1",
117119
"danger-plugin-jest": "^1.0.1",
118120
"danger-plugin-yarn": "^1.3.1",
119121
"date-fns": "^1.29.0",
122+
"eslint": "^8.8.0",
123+
"eslint-config-prettier": "^8.3.0",
124+
"eslint-plugin-jest": "^26.0.0",
125+
"eslint-plugin-jsdoc": "^37.7.0",
120126
"flow-bin": "^0.77.0",
121127
"husky": "^1.0.1",
122128
"jest": "^24.0.0",
@@ -130,8 +136,6 @@
130136
"shx": "^0.3.2",
131137
"ts-jest": "^24.0.2",
132138
"ts-node": "^8.0.2",
133-
"tslint": "^5.11.0",
134-
"tslint-config-prettier": "^1.15.0",
135139
"typedoc": "0.9.0",
136140
"typescript": "^4.5.5",
137141
"typescript-json-schema": "^0.32.0"

source/api/fetch.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ export function api(
6363
url: string | node_fetch.Request,
6464
init: node_fetch.RequestInit,
6565
suppressErrorReporting?: boolean,
66-
provessEnv: NodeJS.ProcessEnv = process.env
66+
processEnv: NodeJS.ProcessEnv = process.env
6767
): Promise<node_fetch.Response> {
6868
const isTests = typeof jest !== "undefined"
6969
if (isTests && !url.toString().includes("localhost")) {
7070
const message = `No API calls in tests please: ${url}`
71-
debugger // tslint:disable-line
71+
debugger
7272
throw new Error(message)
7373
}
7474

@@ -79,8 +79,8 @@ export function api(
7979
output.push(`-X ${init.method}`)
8080
}
8181

82-
const showToken = provessEnv["DANGER_VERBOSE_SHOW_TOKEN"]
83-
const token = provessEnv["DANGER_GITHUB_API_TOKEN"] || provessEnv["GITHUB_TOKEN"]
82+
const showToken = processEnv["DANGER_VERBOSE_SHOW_TOKEN"]
83+
const token = processEnv["DANGER_GITHUB_API_TOKEN"] || processEnv["GITHUB_TOKEN"]
8484

8585
if (init.headers) {
8686
for (const prop in init.headers) {
@@ -109,7 +109,7 @@ export function api(
109109

110110
let agent = init.agent
111111
const proxy =
112-
provessEnv["HTTPS_PROXY"] || provessEnv["https_proxy"] || provessEnv["HTTP_PROXY"] || provessEnv["http_proxy"]
112+
processEnv["HTTPS_PROXY"] || processEnv["https_proxy"] || processEnv["HTTP_PROXY"] || processEnv["http_proxy"]
113113

114114
if (!agent && proxy) {
115115
let secure = url.toString().startsWith("https")

source/ci_source/get_ci_source.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ export async function getCISourceForExternal(env: Env, modulePath: string): Prom
3030
console.error(`could not load CI provider at ${modulePath} due to ${error}`)
3131
}
3232
if (stat && stat.isFile()) {
33-
const externalModule = require(path) //tslint:disable-line:no-require-imports
33+
// eslint-disable-next-line
34+
const externalModule = require(path) // @typescript-eslint/no-var-requires @typescript-eslint/no-require-imports
3435
const moduleConstructor = externalModule.default || externalModule
3536
resolve(new moduleConstructor(env))
3637
}

source/ci_source/providers/_tests/_bamboo.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ describe(".isPR", () => {
5454

5555
it("needs to have a PR number", () => {
5656
let env = Object.assign({}, correctEnv)
57+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
5758
// @ts-ignore
5859
delete env["bamboo_repository_pr_key"]
5960
const pipelines = new Bamboo(env)

source/ci_source/providers/_tests/_buddyWorks.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ describe(".isPR", () => {
5252

5353
it("needs to have a PR number", () => {
5454
const env = Object.assign({}, correctEnv)
55+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
5556
// @ts-ignore
5657
delete env.BUDDY_EXECUTION_PULL_REQUEST_NO
5758
const buddyWorks = new BuddyWorks(env)

source/ci_source/providers/_tests/_codebuild.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const correctEnv = {
99
DANGER_GITHUB_API_TOKEN: "xxx",
1010
}
1111

12-
const setupCodeBuildSource = async (env: Object) => {
12+
const setupCodeBuildSource = async (env: Record<string, unknown>) => {
1313
const source = new CodeBuild(env)
1414
await source.setup()
1515

0 commit comments

Comments
 (0)