Skip to content

Commit

Permalink
Support semicolon option with TypeScript (#446)
Browse files Browse the repository at this point in the history
  • Loading branch information
EdJoPaTo committed Apr 5, 2020
1 parent a4625a7 commit c47a0c6
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
7 changes: 6 additions & 1 deletion lib/options-manager.js
Expand Up @@ -297,7 +297,12 @@ const buildXOConfig = options => config => {
}

if (options.semicolon === false && !options.prettier) {
config.rules.semi = ['error', 'never'];
if (options.ts) {
config.rules['@typescript-eslint/semi'] = ['error', 'never'];
} else {
config.rules.semi = ['error', 'never'];
}

config.rules['semi-spacing'] = ['error', {
before: false,
after: true
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/typescript/child/no-semicolon.ts
@@ -0,0 +1 @@
console.log('no-semicolon')
15 changes: 15 additions & 0 deletions test/lint-files.js
Expand Up @@ -196,6 +196,21 @@ test('typescript files', async t => {
);
});

test('typescript 2 space option', async t => {
const {errorCount} = await fn.lintFiles('two-spaces.tsx', {cwd: 'fixtures/typescript', space: 2});
t.is(errorCount, 0);
});

test('typescript 4 space option', async t => {
const {errorCount} = await fn.lintFiles('child/sub-child/four-spaces.ts', {cwd: 'fixtures/typescript', space: 4});
t.is(errorCount, 0);
});

test('typescript no semicolon option', async t => {
const {errorCount} = await fn.lintFiles('child/no-semicolon.ts', {cwd: 'fixtures/typescript', semicolon: false});
t.is(errorCount, 0);
});

test('webpack import resolver is used if webpack.config.js is found', async t => {
const cwd = 'fixtures/webpack/with-config/';
const {results} = await fn.lintFiles(path.resolve(cwd, 'file1.js'), {
Expand Down
23 changes: 20 additions & 3 deletions test/lint-text.js
Expand Up @@ -270,17 +270,34 @@ test('find configurations close to linted file', t => {

test('typescript files', t => {
let {results} = fn.lintText(`console.log([
2
]);`, {filename: 'fixtures/typescript/two-spaces.tsx'});
2
]);
`, {filename: 'fixtures/typescript/two-spaces.tsx'});
t.true(hasRule(results, '@typescript-eslint/indent'));

({results} = fn.lintText(`console.log([
2
]);
`, {filename: 'fixtures/typescript/two-spaces.tsx', space: 2}));
t.is(results[0].errorCount, 0);

({results} = fn.lintText('console.log(\'extra-semicolon\');;\n', {filename: 'fixtures/typescript/child/extra-semicolon.ts'}));
t.true(hasRule(results, '@typescript-eslint/no-extra-semi'));

({results} = fn.lintText('console.log(\'no-semicolon\')\n', {filename: 'fixtures/typescript/child/no-semicolon.ts', semicolon: false}));
t.is(results[0].errorCount, 0);

({results} = fn.lintText(`console.log([
4
]);`, {filename: 'fixtures/typescript/child/sub-child/four-spaces.ts'}));
]);
`, {filename: 'fixtures/typescript/child/sub-child/four-spaces.ts'}));
t.true(hasRule(results, '@typescript-eslint/indent'));

({results} = fn.lintText(`console.log([
4
]);
`, {filename: 'fixtures/typescript/child/sub-child/four-spaces.ts', space: 4}));
t.is(results[0].errorCount, 0);
});

function configType(t, {dir}) {
Expand Down

0 comments on commit c47a0c6

Please sign in to comment.