Skip to content

Commit f0e14fb

Browse files
committed
chore: add linting
1 parent e257200 commit f0e14fb

File tree

7 files changed

+1034
-229
lines changed

7 files changed

+1034
-229
lines changed

.eslintrc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"parser": "@typescript-eslint/parser",
3+
"extends": [
4+
"eslint:recommended",
5+
"plugin:prettier/recommended"
6+
],
7+
"env": {
8+
"node": true
9+
},
10+
"overrides": [
11+
{
12+
"files": "**/*.ts",
13+
"extends": [
14+
"plugin:@typescript-eslint/eslint-recommended"
15+
]
16+
}
17+
]
18+
}

.github/workflows/nodejs.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Unit tests
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- next
8+
pull_request:
9+
branches:
10+
- main
11+
- next
12+
13+
jobs:
14+
lint:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v2
18+
- uses: actions/setup-node@v2
19+
with:
20+
node-version: 14.x
21+
cache: yarn
22+
- name: install
23+
run: yarn
24+
- name: run ESLint
25+
run: yarn lint

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
node_modules/*
22
.idea/*
33
.vscode/*
4+
*.log
45

package.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,25 @@
99
"Karan Sanjeev Nair <[email protected]> (https://alphaman.me)",
1010
"Saurabh Agarwala <[email protected]>"
1111
],
12+
"scripts": {
13+
"lint": "eslint ."
14+
},
1215
"dependencies": {
1316
"create-jest-runner": "^0.6.0",
1417
"jest-docblock": "^26.0.0",
1518
"mlh-tsd": "^0.14.1"
19+
},
20+
"devDependencies": {
21+
"@typescript-eslint/eslint-plugin": "^5.0.0",
22+
"@typescript-eslint/parser": "^5.0.0",
23+
"eslint": "^7.32.0",
24+
"eslint-config-prettier": "^8.3.0",
25+
"eslint-plugin-prettier": "^3.4.1",
26+
"prettier": "^2.4.1",
27+
"typescript": "^4.4.4"
28+
},
29+
"prettier": {
30+
"arrowParens": "avoid",
31+
"singleQuote": true
1632
}
1733
}

src/fail.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
const { toTestResult } = require('./toTestResult');
22

3-
module.exports.fail = ({ start, end, test, errorMessage, numFailed, numPassed }) => {
3+
module.exports.fail = ({
4+
start,
5+
end,
6+
test,
7+
errorMessage,
8+
numFailed,
9+
numPassed,
10+
}) => {
411
const stats = {
512
failures: numFailed,
613
passes: numPassed,
@@ -14,7 +21,7 @@ module.exports.fail = ({ start, end, test, errorMessage, numFailed, numPassed })
1421
stats,
1522
title: 'Type Checks',
1623
errorMessage: errorMessage.join('\n'),
17-
tests: [{duration: end - start, ...test}],
24+
tests: [{ duration: end - start, ...test }],
1825
jestTestPath: test.path,
1926
});
2027
};

src/run.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@ const findTypingsFile = testPath => {
1515
const parsedDocblocks = parse(fileContents);
1616
const typingsFile = parsedDocblocks.type || '';
1717

18-
if (typingsFile === 'undefined')
19-
return '';
18+
if (typingsFile === 'undefined') return '';
2019

2120
return String(typingsFile);
22-
}
21+
};
2322

2423
module.exports = async ({ testPath }) => {
2524
// Convert absolute path to relative path
@@ -28,7 +27,10 @@ module.exports = async ({ testPath }) => {
2827
const typingsFileRelativePath = findTypingsFile(testPath);
2928

3029
// Remove filename from the path and join it with typingsFile relative path
31-
const typingsFile = join(testFile.substring(0, testFile.lastIndexOf('/')), typingsFileRelativePath);
30+
const typingsFile = join(
31+
testFile.substring(0, testFile.lastIndexOf('/')),
32+
typingsFileRelativePath
33+
);
3234

3335
const extendedDiagnostics = await tsd.default({
3436
cwd: process.cwd(),
@@ -46,14 +48,16 @@ module.exports = async ({ testPath }) => {
4648
let errorMessage = [];
4749

4850
failedTests.forEach(test => {
49-
errorMessage.push(`${testFile}:${test.line}:${test.column} - ${test.severity} - ${test.message}`);
51+
errorMessage.push(
52+
`${testFile}:${test.line}:${test.column} - ${test.severity} - ${test.message}`
53+
);
5054
});
5155

5256
return fail({
5357
start,
5458
end: +new Date(),
5559
test: {
56-
path: testPath
60+
path: testPath,
5761
},
5862
numFailed,
5963
numPassed,

0 commit comments

Comments
 (0)