Skip to content

Commit 92a3a9e

Browse files
switch to eslint
1 parent bd07d2c commit 92a3a9e

Some content is hidden

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

58 files changed

+914
-669
lines changed

.eslintignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
**/node_modules
2+
**/dist

.eslintrc

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{
2+
"parser": "@typescript-eslint/parser",
3+
4+
"parserOptions": {
5+
"project": "./tsconfig.json",
6+
"sourceType": "module"
7+
},
8+
9+
"extends": [
10+
"xo",
11+
"plugin:jest/recommended",
12+
"plugin:@typescript-eslint/recommended",
13+
"prettier",
14+
"prettier/@typescript-eslint"
15+
],
16+
17+
"plugins": ["prettier", "jest", "@typescript-eslint"],
18+
19+
"rules": {
20+
/* xo config */
21+
22+
// makes commenting out lines quickly a hassle
23+
"capitalized-comments": 0,
24+
"default-param-last": 0,
25+
"complexity": ["error", { "max": 25 }],
26+
27+
/* jest plugin */
28+
29+
"jest/no-empty-title": 2,
30+
"jest/prefer-strict-equal": 2,
31+
"jest/prefer-spy-on": 2,
32+
"jest/no-standalone-expect": 2,
33+
"jest/no-try-expect": 2,
34+
"jest/no-export": 2,
35+
"jest/no-truthy-falsy": 1,
36+
"jest/no-duplicate-hooks": 1,
37+
"jest/no-if": 1,
38+
"jest/prefer-to-have-length": 1,
39+
40+
/* typescript */
41+
42+
"@typescript-eslint/no-this-alias": 2,
43+
"@typescript-eslint/no-unnecessary-type-assertion": 2,
44+
"@typescript-eslint/no-useless-constructor": 2,
45+
// if we turn this on babel adds regeneratorRuntime which makes builds harder and larger
46+
"@typescript-eslint/promise-function-async": 0,
47+
// just rely on typescript inference
48+
"@typescript-eslint/explicit-function-return-type": 0,
49+
"@typescript-eslint/camelcase": 0,
50+
"@typescript-eslint/interface-name-prefix": 0,
51+
"@typescript-eslint/no-non-null-assertion": 0,
52+
"@typescript-eslint/explicit-member-accessibility": 0
53+
},
54+
55+
"overrides": [
56+
{
57+
"files": ["*.test.*"],
58+
"rules": {
59+
"@typescript-eslint/no-non-null-assertion": 0,
60+
"@typescript-eslint/no-explicit-any": 0,
61+
"require-atomic-updates": 0,
62+
"max-nested-callbacks": 0,
63+
"@typescript-eslint/ban-ts-ignore": 0
64+
}
65+
}
66+
]
67+
}

package.json

+11-6
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"semver:check": "./scripts/post-install.sh",
2727
"build": "tsc -b tsconfig.dev.json",
2828
"start": "npm run build -- --watch",
29-
"lint": "tslint -p . --format stylish",
29+
"lint": "eslint packages plugins --ext .ts",
3030
"precommit": "lint-staged",
3131
"test": "jest --runInBand",
3232
"release": "chmod +x ./packages/cli/dist/bin/auto.js && ./packages/cli/dist/bin/auto.js shipit",
@@ -38,22 +38,27 @@
3838
"create:plugin": "./scripts/create-plugin.js"
3939
},
4040
"devDependencies": {
41+
"@typescript-eslint/eslint-plugin": "^2.4.0",
42+
"@typescript-eslint/parser": "^2.4.0",
4143
"all-contributors-cli": "^6.4.0",
4244
"change-case": "^3.1.0",
4345
"copy-template-dir": "^1.4.0",
46+
"eslint": "^6.5.1",
47+
"eslint-config-prettier": "^6.4.0",
48+
"eslint-config-xo": "^0.27.1",
49+
"eslint-plugin-import": "^2.18.2",
50+
"eslint-plugin-jest": "^22.19.0",
51+
"eslint-plugin-prettier": "^3.1.1",
4452
"graphql": "^14.2.1",
4553
"husky": "^3.0.3",
4654
"ignite": "^1.10.2",
4755
"jest": "~24.9.0",
4856
"lerna": "^3.13.4",
4957
"lint-staged": "^9.4.0",
5058
"prettier": "^1.16.4",
59+
"rimraf": "^3.0.0",
5160
"ts-jest": "^24.0.2",
52-
"tslint": "~5.20.0",
53-
"tslint-config-prettier": "~1.18.0",
54-
"tslint-xo": "~0.16.0",
55-
"typescript": "~3.6.2",
56-
"typescript-tslint-plugin": "^0.5.4"
61+
"typescript": "~3.6.2"
5762
},
5863
"prettier": {
5964
"singleQuote": true

packages/cli/__tests__/args.test.ts

+16-21
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,32 @@
11
import parseArgs from '../src/parse-args';
22

3+
const log = jest.fn();
4+
// @ts-ignore
5+
global.console = { log };
6+
37
describe('root parser', () => {
4-
test('should print version', () => {
5-
console.log = jest.fn();
8+
beforeEach(() => {
9+
log.mockClear();
10+
});
611

12+
test('should print version', () => {
713
parseArgs('--version'.split(' '));
8-
9-
expect(console.log).toHaveBeenCalled();
14+
expect(log).toHaveBeenCalled();
1015
});
1116

1217
test('should print help', () => {
13-
console.log = jest.fn();
14-
1518
parseArgs('--help'.split(' '));
16-
17-
expect(console.log).toHaveBeenCalled();
19+
expect(log).toHaveBeenCalled();
1820
});
1921

2022
test('should print help for simple command', () => {
21-
console.log = jest.fn();
22-
2323
parseArgs('init --help'.split(' '));
24-
25-
expect(console.log).toHaveBeenCalled();
24+
expect(log).toHaveBeenCalled();
2625
});
2726

2827
test('should print help for complex command', () => {
29-
console.log = jest.fn();
30-
3128
parseArgs('pr --help'.split(' '));
32-
33-
expect(console.log).toHaveBeenCalled();
29+
expect(log).toHaveBeenCalled();
3430
});
3531

3632
test('should exit when required arg is not included', () => {
@@ -40,14 +36,13 @@ describe('root parser', () => {
4036
});
4137

4238
test('should exit when required string is provided as flag', () => {
43-
console.log = jest.fn() as any;
4439
process.exit = jest.fn() as any;
4540
parseArgs(['pr-check', '--pr', '24', '--url']);
4641
expect(process.exit).toHaveBeenCalled();
4742
});
4843

4944
test('should parse just provided args', () => {
50-
expect(parseArgs('label --pr 2 --owner adam'.split(' '))).toEqual([
45+
expect(parseArgs('label --pr 2 --owner adam'.split(' '))).toStrictEqual([
5146
'label',
5247
{
5348
pr: 2,
@@ -57,7 +52,7 @@ describe('root parser', () => {
5752
});
5853

5954
test('should parse args as camelCase', () => {
60-
expect(parseArgs('changelog -d'.split(' '))).toEqual([
55+
expect(parseArgs('changelog -d'.split(' '))).toStrictEqual([
6156
'changelog',
6257
{
6358
dryRun: true
@@ -72,7 +67,7 @@ describe('root parser', () => {
7267
});
7368

7469
test('allow array of options to or', () => {
75-
expect(parseArgs(['comment', '--message', 'foo'])).toEqual([
70+
expect(parseArgs(['comment', '--message', 'foo'])).toStrictEqual([
7671
'comment',
7772
{
7873
message: 'foo'
@@ -81,7 +76,7 @@ describe('root parser', () => {
8176
});
8277

8378
test('allow edit in comment', () => {
84-
expect(parseArgs(['comment', '--edit', '--message', 'foo'])).toEqual([
79+
expect(parseArgs(['comment', '--edit', '--message', 'foo'])).toStrictEqual([
8580
'comment',
8681
{
8782
edit: true,

packages/cli/__tests__/main.test.ts

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
import main, { run } from '../src/run';
22

33
test('throws error for unknown args', async () => {
4-
expect.assertions(1);
5-
6-
try {
7-
await run('foo', {});
8-
} catch (error) {
9-
expect(error).toEqual(new Error("idk what i'm doing."));
10-
}
4+
await expect(run('foo', {})).rejects.toStrictEqual(
5+
new Error("idk what i'm doing.")
6+
);
117
});
128

139
test('throws exits for caught error', async () => {

packages/cli/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"scripts": {
3636
"build": "tsc -b",
3737
"start": "npm run build -- -w",
38-
"lint": "tslint -p . --format stylish",
38+
"lint": "eslint src --ext .ts",
3939
"test": "jest --maxWorkers=2",
4040
"bundle": "rimraf binary && pkg . --out-path binary && yarn gzip",
4141
"gzip": "ls binary/auto* | xargs gzip"

packages/cli/src/parse-args.ts

+24-24
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,30 @@ function filterCommands(allCommands: ICommand[], include: string[]) {
515515
}));
516516
}
517517

518+
function styleTypes(
519+
command: ICommand,
520+
option: commandLineUsage.OptionDefinition
521+
) {
522+
const isRequired =
523+
command.require && command.require.includes(option.name as Flags);
524+
525+
if (isRequired && option.type === Number) {
526+
option.typeLabel =
527+
'{rgb(173, 216, 230) {underline number}} [{rgb(254,91,92) required}]';
528+
} else if (option.type === Number) {
529+
option.typeLabel = '{rgb(173, 216, 230) {underline number}}';
530+
}
531+
532+
if (isRequired && option.type === String) {
533+
option.typeLabel =
534+
'{rgb(173, 216, 230) {underline string}} [{rgb(254,91,92) required}]';
535+
} else if (option.multiple && option.type === String) {
536+
option.typeLabel = '{rgb(173, 216, 230) {underline string[]}}';
537+
} else if (option.type === String) {
538+
option.typeLabel = '{rgb(173, 216, 230) {underline string}}';
539+
}
540+
}
541+
518542
function printRootHelp() {
519543
const options = [
520544
{ ...version, group: 'misc' },
@@ -621,30 +645,6 @@ function printVersion() {
621645
console.log(`v${packageJson.version}`);
622646
}
623647

624-
function styleTypes(
625-
command: ICommand,
626-
option: commandLineUsage.OptionDefinition
627-
) {
628-
const isRequired =
629-
command.require && command.require.includes(option.name as Flags);
630-
631-
if (isRequired && option.type === Number) {
632-
option.typeLabel =
633-
'{rgb(173, 216, 230) {underline number}} [{rgb(254,91,92) required}]';
634-
} else if (option.type === Number) {
635-
option.typeLabel = '{rgb(173, 216, 230) {underline number}}';
636-
}
637-
638-
if (isRequired && option.type === String) {
639-
option.typeLabel =
640-
'{rgb(173, 216, 230) {underline string}} [{rgb(254,91,92) required}]';
641-
} else if (option.multiple && option.type === String) {
642-
option.typeLabel = '{rgb(173, 216, 230) {underline string[]}}';
643-
} else if (option.type === String) {
644-
option.typeLabel = '{rgb(173, 216, 230) {underline string}}';
645-
}
646-
}
647-
648648
export default function parseArgs(testArgs?: string[]) {
649649
const mainOptions = commandLineArgs(mainDefinitions, {
650650
stopAtFirstUnknown: true,

packages/core/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"scripts": {
3333
"build": "tsc -b",
3434
"start": "npm run build -- -w",
35-
"lint": "tslint -p . --format stylish",
35+
"lint": "eslint src --ext .ts",
3636
"test": "jest --maxWorkers=2 --config ../../package.json"
3737
},
3838
"dependencies": {

packages/core/src/__tests__/auto-canary-in-pr-ci.test.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe('canary in ci', () => {
2828
auto.hooks.canary.tap('test', canary);
2929
const addToPrBody = jest.fn();
3030
auto.git!.addToPrBody = addToPrBody;
31-
auto.release!.getCommits = jest.fn();
31+
jest.spyOn(auto.release!, 'getCommits').mockImplementation();
3232

3333
await auto.canary();
3434
expect(canary).toHaveBeenCalledWith(SEMVER.patch, '.123.1');
@@ -43,7 +43,7 @@ describe('canary in ci', () => {
4343
Promise.resolve([makeCommitFromMsg('Test Commit')]);
4444
const addToPrBody = jest.fn();
4545
auto.git!.addToPrBody = addToPrBody;
46-
auto.release!.getCommits = jest.fn();
46+
jest.spyOn(auto.release!, 'getCommits').mockImplementation();
4747
auto.hooks.canary.tap('test', () => '1.2.4-canary.123.1');
4848

4949
const version = await auto.canary({ pr: 123, build: 1 });
@@ -60,7 +60,7 @@ describe('canary in ci', () => {
6060
Promise.resolve([makeCommitFromMsg('Test Commit')]);
6161
const addToPrBody = jest.fn();
6262
auto.git!.addToPrBody = addToPrBody;
63-
auto.release!.getCommits = jest.fn();
63+
jest.spyOn(auto.release!, 'getCommits').mockImplementation();
6464

6565
await auto.canary({ pr: 123, build: 1, message: 'false' });
6666
expect(addToPrBody).not.toHaveBeenCalled();
@@ -74,7 +74,7 @@ describe('canary in ci', () => {
7474
Promise.resolve([makeCommitFromMsg('Test Commit')]);
7575
const addToPrBody = jest.fn();
7676
auto.git!.addToPrBody = addToPrBody;
77-
auto.release!.getCommits = jest.fn();
77+
jest.spyOn(auto.release!, 'getCommits').mockImplementation();
7878
auto.hooks.canary.tap('test', (bump, post) => `1.2.4-canary${post}`);
7979

8080
const version = await auto.canary({ pr: 456, build: 5 });
@@ -89,7 +89,7 @@ describe('shipit in ci', () => {
8989
await auto.loadConfig();
9090

9191
auto.git!.getLatestRelease = () => Promise.resolve('1.2.3');
92-
auto.git!.addToPrBody = jest.fn();
92+
jest.spyOn(auto.git!, 'addToPrBody').mockImplementation();
9393
auto.release!.getCommitsInRelease = () => Promise.resolve([]);
9494
auto.release!.getCommits = () => Promise.resolve([]);
9595
const canary = jest.fn();

packages/core/src/__tests__/auto-canary-local.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ test('shipit should publish canary in locally when not on master', async () => {
1919

2020
auto.git!.getLatestRelease = () => Promise.resolve('1.2.3');
2121
auto.git!.getSha = () => Promise.resolve('abc');
22-
auto.git!.createComment = jest.fn();
22+
jest.spyOn(auto.git!, 'createComment').mockImplementation();
2323
auto.release!.getCommitsInRelease = () => Promise.resolve([]);
2424
auto.release!.getCommits = () => Promise.resolve([]);
2525
const canary = jest.fn();

0 commit comments

Comments
 (0)