Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support semicolon option with TypeScript #446

Merged
merged 4 commits into from Apr 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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) {
EdJoPaTo marked this conversation as resolved.
Show resolved Hide resolved
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