Skip to content

Commit

Permalink
fixy
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith committed Dec 30, 2019
1 parent fac5b66 commit d8a3dbd
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 26 deletions.
53 changes: 53 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
},
"devDependencies": {
"@npm/types": "^1.0.1",
"@types/chai": "^4.2.7",
"@types/cross-spawn": "^6.0.0",
"@types/eslint": "^6.1.3",
"@types/fs-extra": "^8.0.0",
Expand All @@ -72,6 +73,7 @@
"@types/write-file-atomic": "^2.1.2",
"assert-rejects": "^1.0.0",
"c8": "^7.0.0",
"chai": "^4.2.0",
"codecov": "^3.0.1",
"cross-spawn": "^7.0.0",
"fs-extra": "^8.0.0",
Expand Down
15 changes: 6 additions & 9 deletions src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,8 @@ async function writePackageJson(
options.logger.dir(preview);
}

export const TSLINT_CONFIG = {
extends: 'gts/tslint.json',
linterOptions: {
exclude: ['**/*.json'],
},
export const ESLINT_CONFIG = {
extends: './node_modules/gts/build/src/index.js',
};

async function generateConfigFile(
Expand Down Expand Up @@ -223,11 +220,11 @@ async function generateConfigFile(
}
}

async function generateTsLintConfig(options: Options): Promise<void> {
async function generateESLintConfig(options: Options): Promise<void> {
return generateConfigFile(
options,
'./tslint.json',
formatJson(TSLINT_CONFIG)
'./.eslintrc.json',
formatJson(ESLINT_CONFIG)
);
}

Expand Down Expand Up @@ -312,7 +309,7 @@ export async function init(options: Options): Promise<boolean> {
options.logger.log('No edits needed in package.json.');
}
await generateTsConfig(options);
await generateTsLintConfig(options);
await generateESLintConfig(options);
await generatePrettierConfig(options);
await installDefaultTemplate(options);

Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/kitchen/src/server.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
const isThisTypeScript = true;
const isThisTypeScript = true
28 changes: 12 additions & 16 deletions test/kitchen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import chalk = require('chalk');
import * as cp from 'child_process';
import * as fs from 'fs-extra';
import * as tmp from 'tmp';
import * as assert from 'assert';
import { assert } from 'chai';
import * as path from 'path';
import { describe, it, before, after } from 'mocha';

import spawn = require('cross-spawn');
import execa = require('execa');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const pkg = require('../../package.json');
const keep = !!process.env.GTS_KEEP_TEMPDIRS;
Expand All @@ -17,15 +18,14 @@ const execOpts = {
encoding: 'utf8',
};

console.log(`${chalk.blue(`${__filename} staging area: ${stagingPath}`)}`);

describe('🚰 kitchen sink', () => {
const fixturesPath = path.join('test', 'fixtures');
const gtsPath = path.join('node_modules', '.bin', 'gts');
const kitchenPath = path.join(stagingPath, 'kitchen');

// Create a staging directory with temp fixtures used to test on a fresh application.
before(() => {
console.log(`${chalk.blue(`${__filename} staging area: ${stagingPath}`)}`);
cp.execSync('npm pack');
const tarball = `${pkg.name}-${pkg.version}.tgz`;
fs.renameSync(tarball, 'gts.tgz');
Expand Down Expand Up @@ -59,7 +59,7 @@ describe('🚰 kitchen sink', () => {

// Ensure config files got generated.
fs.accessSync(path.join(kitchenPath, 'tsconfig.json'));
fs.accessSync(path.join(kitchenPath, 'tslint.json'));
fs.accessSync(path.join(kitchenPath, '.eslintrc.json'));
fs.accessSync(path.join(kitchenPath, 'prettier.config.js'));

// Compilation shouldn't have happened. Hence no `build` directory.
Expand Down Expand Up @@ -119,23 +119,19 @@ describe('🚰 kitchen sink', () => {
);
assert.ok(
fs
.readFileSync(path.join(kitchenPath, 'tslint.json'), 'utf8')
.readFileSync(path.join(kitchenPath, '.eslintrc.json'), 'utf8')
.endsWith('\n')
);
});

it('should check before fix', () => {
assert.throws(
() => {
cp.execSync('npm run check', execOpts);
},
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(err: any) => {
assert.strictEqual(err.status, 1);
assert.ok(err.stdout.includes('prettier reported errors'));
return true;
}
it('should check before fix', async () => {
const res = await execa(
'npm',
['run', 'check'],
Object.assign({}, { reject: false }, execOpts)
);
assert.strictEqual(res.exitCode, 1);
assert.include(res.stdout, 'assigned a value but');
});

it('should fix', () => {
Expand Down

0 comments on commit d8a3dbd

Please sign in to comment.