From c527b66be1ef6a78ea14b3d29225a8d7fb7097bd Mon Sep 17 00:00:00 2001 From: Justin Beckwith Date: Wed, 7 Oct 2020 20:15:56 -0700 Subject: [PATCH] feat!: change default `check` to `lint` (#570) --- README.md | 8 ++++---- src/cli.ts | 6 ++++-- src/init.ts | 6 +++--- template/index.ts | 2 +- test/kitchen.ts | 10 +++++----- test/test-init.ts | 20 +++++++------------- 6 files changed, 24 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index c38eb540..45362a7a 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ When you run the `npx gts init` command, it's going to do a few things for you: - Adds an opinionated `tsconfig.json` file to your project that uses the Google TypeScript Style. - Adds the necessary devDependencies to your `package.json`. - Adds scripts to your `package.json`: - - `check`: Lints and checks for formatting problems. + - `lint`: Lints and checks for formatting problems. - `fix`: Automatically fixes formatting and linting problems (if possible). - `clean`: Removes output files. - `compile`: Compiles the source code using TypeScript compiler. @@ -41,9 +41,9 @@ When you run the `npx gts init` command, it's going to do a few things for you: The commands above will all run in the scope of the current folder. Some commands can be run on individual files: ```sh -gts check index.ts -gts check one.ts two.ts three.ts -gts check *.ts +gts lint index.ts +gts lint one.ts two.ts three.ts +gts lint *.ts ``` ### Working with eslint diff --git a/src/cli.ts b/src/cli.ts index ccbccedf..ef4d7284 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -58,7 +58,8 @@ const cli = meow({ Verb can be: init Adds default npm scripts to your package.json. - check Checks code for formatting and lint issues. + lint Checks code for formatting and lint issues. + check Alias for lint. Kept for backward compatibility. fix Fixes formatting and linting issues (if possible). clean Removes all files generated by the build. @@ -71,7 +72,7 @@ const cli = meow({ Examples $ gts init -y - $ gts check + $ gts lint $ gts fix $ gts fix src/file1.ts src/file2.ts $ gts clean`, @@ -141,6 +142,7 @@ export async function run(verb: string, files: string[]): Promise { } switch (verb) { + case 'lint': case 'check': { try { await execa('node', ['./node_modules/eslint/bin/eslint', ...flags], { diff --git a/src/init.ts b/src/init.ts index b7b5fa4f..789b6f5b 100644 --- a/src/init.ts +++ b/src/init.ts @@ -82,13 +82,13 @@ export async function addScripts( let edits = false; const pkgManager = getPkgManagerCommand(options.yarn); const scripts: Bag = { - check: 'gts check', + lint: 'gts lint', clean: 'gts clean', compile: 'tsc', fix: 'gts fix', prepare: `${pkgManager} run compile`, pretest: `${pkgManager} run compile`, - posttest: `${pkgManager} run check`, + posttest: `${pkgManager} run lint`, }; if (!packageJson.scripts) { @@ -319,7 +319,7 @@ export async function init(options: Options): Promise { await generatePrettierConfig(options); await installDefaultTemplate(options); - // Run `npm install` after initial setup so `npm run check` works right away. + // Run `npm install` after initial setup so `npm run lint` works right away. if (!options.dryRun) { // --ignore-scripts so that compilation doesn't happen because there's no // source files yet. diff --git a/template/index.ts b/template/index.ts index 2c1da126..e8002602 100644 --- a/template/index.ts +++ b/template/index.ts @@ -1,4 +1,4 @@ -console.log('Try npm run check/fix!'); +console.log('Try npm run lint/fix!'); const longString = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer ut aliquet diam.'; diff --git a/test/kitchen.ts b/test/kitchen.ts index 956dc20c..9b8ecd33 100644 --- a/test/kitchen.ts +++ b/test/kitchen.ts @@ -101,7 +101,7 @@ describe('🚰 kitchen sink', () => { ); // server.ts has a lint error. Should error. - assert.throws(() => cp.execSync(`${GTS} check src/server.ts`, opts)); + assert.throws(() => cp.execSync(`${GTS} lint src/server.ts`, opts)); if (!keep) { tmpDir.removeCallback(); @@ -138,10 +138,10 @@ describe('🚰 kitchen sink', () => { ); }); - it('should check before fix', async () => { + it('should lint before fix', async () => { const res = await execa( 'npm', - ['run', 'check'], + ['run', 'lint'], Object.assign({}, {reject: false}, execOpts) ); assert.strictEqual(res.exitCode, 1); @@ -160,8 +160,8 @@ describe('🚰 kitchen sink', () => { assert.strictEqual(preFix[0].trim() + ';', postFix[0]); // fix should have added a semi-colon }); - it('should check after fix', () => { - cp.execSync('npm run check', execOpts); + it('should lint after fix', () => { + cp.execSync('npm run lint', execOpts); }); it('should build', () => { diff --git a/test/test-init.ts b/test/test-init.ts index 35036d7b..7bc80b70 100644 --- a/test/test-init.ts +++ b/test/test-init.ts @@ -44,15 +44,9 @@ const MINIMAL_PACKAGE_JSON = {name: 'name', version: 'v1.1.1'}; function hasExpectedScripts(packageJson: PackageJson): boolean { return ( !!packageJson.scripts && - [ - 'check', - 'clean', - 'compile', - 'fix', - 'prepare', - 'pretest', - 'posttest', - ].every(s => !!packageJson.scripts![s]) + ['lint', 'clean', 'compile', 'fix', 'prepare', 'pretest', 'posttest'].every( + s => !!packageJson.scripts![s] + ) ); } @@ -84,13 +78,13 @@ describe('init', () => { it('addScripts should not edit existing scripts on no', async () => { const SCRIPTS = { - check: 'fake check', + lint: 'fake lint', clean: 'fake clean', compile: 'fake tsc', fix: 'fake fix', prepare: 'fake run compile', pretest: 'fake run compile', - posttest: 'fake run check', + posttest: 'fake run lint', }; const pkg: PackageJson = { ...MINIMAL_PACKAGE_JSON, @@ -103,13 +97,13 @@ describe('init', () => { it('addScripts should edit existing scripts on yes', async () => { const SCRIPTS = { - check: 'fake check', + lint: 'fake lint', clean: 'fake clean', compile: 'fake tsc', fix: 'fake fix', prepare: 'fake run compile', pretest: 'fake run compile', - posttest: 'fake run check', + posttest: 'fake run lint', }; const pkg: PackageJson = { ...MINIMAL_PACKAGE_JSON,