Skip to content

Commit

Permalink
switch to eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
hipstersmoothie committed Oct 16, 2019
1 parent bd07d2c commit 92a3a9e
Show file tree
Hide file tree
Showing 58 changed files with 914 additions and 669 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
**/node_modules
**/dist
67 changes: 67 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"parser": "@typescript-eslint/parser",

"parserOptions": {
"project": "./tsconfig.json",
"sourceType": "module"
},

"extends": [
"xo",
"plugin:jest/recommended",
"plugin:@typescript-eslint/recommended",
"prettier",
"prettier/@typescript-eslint"
],

"plugins": ["prettier", "jest", "@typescript-eslint"],

"rules": {
/* xo config */

// makes commenting out lines quickly a hassle
"capitalized-comments": 0,
"default-param-last": 0,
"complexity": ["error", { "max": 25 }],

/* jest plugin */

"jest/no-empty-title": 2,
"jest/prefer-strict-equal": 2,
"jest/prefer-spy-on": 2,
"jest/no-standalone-expect": 2,
"jest/no-try-expect": 2,
"jest/no-export": 2,
"jest/no-truthy-falsy": 1,
"jest/no-duplicate-hooks": 1,
"jest/no-if": 1,
"jest/prefer-to-have-length": 1,

/* typescript */

"@typescript-eslint/no-this-alias": 2,
"@typescript-eslint/no-unnecessary-type-assertion": 2,
"@typescript-eslint/no-useless-constructor": 2,
// if we turn this on babel adds regeneratorRuntime which makes builds harder and larger
"@typescript-eslint/promise-function-async": 0,
// just rely on typescript inference
"@typescript-eslint/explicit-function-return-type": 0,
"@typescript-eslint/camelcase": 0,
"@typescript-eslint/interface-name-prefix": 0,
"@typescript-eslint/no-non-null-assertion": 0,
"@typescript-eslint/explicit-member-accessibility": 0
},

"overrides": [
{
"files": ["*.test.*"],
"rules": {
"@typescript-eslint/no-non-null-assertion": 0,
"@typescript-eslint/no-explicit-any": 0,
"require-atomic-updates": 0,
"max-nested-callbacks": 0,
"@typescript-eslint/ban-ts-ignore": 0
}
}
]
}
17 changes: 11 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"semver:check": "./scripts/post-install.sh",
"build": "tsc -b tsconfig.dev.json",
"start": "npm run build -- --watch",
"lint": "tslint -p . --format stylish",
"lint": "eslint packages plugins --ext .ts",
"precommit": "lint-staged",
"test": "jest --runInBand",
"release": "chmod +x ./packages/cli/dist/bin/auto.js && ./packages/cli/dist/bin/auto.js shipit",
Expand All @@ -38,22 +38,27 @@
"create:plugin": "./scripts/create-plugin.js"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^2.4.0",
"@typescript-eslint/parser": "^2.4.0",
"all-contributors-cli": "^6.4.0",
"change-case": "^3.1.0",
"copy-template-dir": "^1.4.0",
"eslint": "^6.5.1",
"eslint-config-prettier": "^6.4.0",
"eslint-config-xo": "^0.27.1",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-jest": "^22.19.0",
"eslint-plugin-prettier": "^3.1.1",
"graphql": "^14.2.1",
"husky": "^3.0.3",
"ignite": "^1.10.2",
"jest": "~24.9.0",
"lerna": "^3.13.4",
"lint-staged": "^9.4.0",
"prettier": "^1.16.4",
"rimraf": "^3.0.0",
"ts-jest": "^24.0.2",
"tslint": "~5.20.0",
"tslint-config-prettier": "~1.18.0",
"tslint-xo": "~0.16.0",
"typescript": "~3.6.2",
"typescript-tslint-plugin": "^0.5.4"
"typescript": "~3.6.2"
},
"prettier": {
"singleQuote": true
Expand Down
37 changes: 16 additions & 21 deletions packages/cli/__tests__/args.test.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,32 @@
import parseArgs from '../src/parse-args';

const log = jest.fn();
// @ts-ignore
global.console = { log };

describe('root parser', () => {
test('should print version', () => {
console.log = jest.fn();
beforeEach(() => {
log.mockClear();
});

test('should print version', () => {
parseArgs('--version'.split(' '));

expect(console.log).toHaveBeenCalled();
expect(log).toHaveBeenCalled();
});

test('should print help', () => {
console.log = jest.fn();

parseArgs('--help'.split(' '));

expect(console.log).toHaveBeenCalled();
expect(log).toHaveBeenCalled();
});

test('should print help for simple command', () => {
console.log = jest.fn();

parseArgs('init --help'.split(' '));

expect(console.log).toHaveBeenCalled();
expect(log).toHaveBeenCalled();
});

test('should print help for complex command', () => {
console.log = jest.fn();

parseArgs('pr --help'.split(' '));

expect(console.log).toHaveBeenCalled();
expect(log).toHaveBeenCalled();
});

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

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

test('should parse just provided args', () => {
expect(parseArgs('label --pr 2 --owner adam'.split(' '))).toEqual([
expect(parseArgs('label --pr 2 --owner adam'.split(' '))).toStrictEqual([
'label',
{
pr: 2,
Expand All @@ -57,7 +52,7 @@ describe('root parser', () => {
});

test('should parse args as camelCase', () => {
expect(parseArgs('changelog -d'.split(' '))).toEqual([
expect(parseArgs('changelog -d'.split(' '))).toStrictEqual([
'changelog',
{
dryRun: true
Expand All @@ -72,7 +67,7 @@ describe('root parser', () => {
});

test('allow array of options to or', () => {
expect(parseArgs(['comment', '--message', 'foo'])).toEqual([
expect(parseArgs(['comment', '--message', 'foo'])).toStrictEqual([
'comment',
{
message: 'foo'
Expand All @@ -81,7 +76,7 @@ describe('root parser', () => {
});

test('allow edit in comment', () => {
expect(parseArgs(['comment', '--edit', '--message', 'foo'])).toEqual([
expect(parseArgs(['comment', '--edit', '--message', 'foo'])).toStrictEqual([
'comment',
{
edit: true,
Expand Down
10 changes: 3 additions & 7 deletions packages/cli/__tests__/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import main, { run } from '../src/run';

test('throws error for unknown args', async () => {
expect.assertions(1);

try {
await run('foo', {});
} catch (error) {
expect(error).toEqual(new Error("idk what i'm doing."));
}
await expect(run('foo', {})).rejects.toStrictEqual(
new Error("idk what i'm doing.")
);
});

test('throws exits for caught error', async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"scripts": {
"build": "tsc -b",
"start": "npm run build -- -w",
"lint": "tslint -p . --format stylish",
"lint": "eslint src --ext .ts",
"test": "jest --maxWorkers=2",
"bundle": "rimraf binary && pkg . --out-path binary && yarn gzip",
"gzip": "ls binary/auto* | xargs gzip"
Expand Down
48 changes: 24 additions & 24 deletions packages/cli/src/parse-args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,30 @@ function filterCommands(allCommands: ICommand[], include: string[]) {
}));
}

function styleTypes(
command: ICommand,
option: commandLineUsage.OptionDefinition
) {
const isRequired =
command.require && command.require.includes(option.name as Flags);

if (isRequired && option.type === Number) {
option.typeLabel =
'{rgb(173, 216, 230) {underline number}} [{rgb(254,91,92) required}]';
} else if (option.type === Number) {
option.typeLabel = '{rgb(173, 216, 230) {underline number}}';
}

if (isRequired && option.type === String) {
option.typeLabel =
'{rgb(173, 216, 230) {underline string}} [{rgb(254,91,92) required}]';
} else if (option.multiple && option.type === String) {
option.typeLabel = '{rgb(173, 216, 230) {underline string[]}}';
} else if (option.type === String) {
option.typeLabel = '{rgb(173, 216, 230) {underline string}}';
}
}

function printRootHelp() {
const options = [
{ ...version, group: 'misc' },
Expand Down Expand Up @@ -621,30 +645,6 @@ function printVersion() {
console.log(`v${packageJson.version}`);
}

function styleTypes(
command: ICommand,
option: commandLineUsage.OptionDefinition
) {
const isRequired =
command.require && command.require.includes(option.name as Flags);

if (isRequired && option.type === Number) {
option.typeLabel =
'{rgb(173, 216, 230) {underline number}} [{rgb(254,91,92) required}]';
} else if (option.type === Number) {
option.typeLabel = '{rgb(173, 216, 230) {underline number}}';
}

if (isRequired && option.type === String) {
option.typeLabel =
'{rgb(173, 216, 230) {underline string}} [{rgb(254,91,92) required}]';
} else if (option.multiple && option.type === String) {
option.typeLabel = '{rgb(173, 216, 230) {underline string[]}}';
} else if (option.type === String) {
option.typeLabel = '{rgb(173, 216, 230) {underline string}}';
}
}

export default function parseArgs(testArgs?: string[]) {
const mainOptions = commandLineArgs(mainDefinitions, {
stopAtFirstUnknown: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"scripts": {
"build": "tsc -b",
"start": "npm run build -- -w",
"lint": "tslint -p . --format stylish",
"lint": "eslint src --ext .ts",
"test": "jest --maxWorkers=2 --config ../../package.json"
},
"dependencies": {
Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/__tests__/auto-canary-in-pr-ci.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('canary in ci', () => {
auto.hooks.canary.tap('test', canary);
const addToPrBody = jest.fn();
auto.git!.addToPrBody = addToPrBody;
auto.release!.getCommits = jest.fn();
jest.spyOn(auto.release!, 'getCommits').mockImplementation();

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

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

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

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

auto.git!.getLatestRelease = () => Promise.resolve('1.2.3');
auto.git!.addToPrBody = jest.fn();
jest.spyOn(auto.git!, 'addToPrBody').mockImplementation();
auto.release!.getCommitsInRelease = () => Promise.resolve([]);
auto.release!.getCommits = () => Promise.resolve([]);
const canary = jest.fn();
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/__tests__/auto-canary-local.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ test('shipit should publish canary in locally when not on master', async () => {

auto.git!.getLatestRelease = () => Promise.resolve('1.2.3');
auto.git!.getSha = () => Promise.resolve('abc');
auto.git!.createComment = jest.fn();
jest.spyOn(auto.git!, 'createComment').mockImplementation();
auto.release!.getCommitsInRelease = () => Promise.resolve([]);
auto.release!.getCommits = () => Promise.resolve([]);
const canary = jest.fn();
Expand Down
Loading

0 comments on commit 92a3a9e

Please sign in to comment.