Skip to content

Commit

Permalink
feat!: change default check to lint (#570)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith committed Oct 8, 2020
1 parent aac8d1b commit c527b66
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 28 deletions.
8 changes: 4 additions & 4 deletions README.md
Expand Up @@ -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.
Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/cli.ts
Expand Up @@ -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.
Expand All @@ -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`,
Expand Down Expand Up @@ -141,6 +142,7 @@ export async function run(verb: string, files: string[]): Promise<boolean> {
}

switch (verb) {
case 'lint':
case 'check': {
try {
await execa('node', ['./node_modules/eslint/bin/eslint', ...flags], {
Expand Down
6 changes: 3 additions & 3 deletions src/init.ts
Expand Up @@ -82,13 +82,13 @@ export async function addScripts(
let edits = false;
const pkgManager = getPkgManagerCommand(options.yarn);
const scripts: Bag<string> = {
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) {
Expand Down Expand Up @@ -319,7 +319,7 @@ export async function init(options: Options): Promise<boolean> {
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.
Expand Down
2 changes: 1 addition & 1 deletion 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.';
Expand Down
10 changes: 5 additions & 5 deletions test/kitchen.ts
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand All @@ -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', () => {
Expand Down
20 changes: 7 additions & 13 deletions test/test-init.ts
Expand Up @@ -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]
)
);
}

Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit c527b66

Please sign in to comment.