Skip to content

Commit

Permalink
address review
Browse files Browse the repository at this point in the history
  • Loading branch information
bradzacher committed Sep 4, 2022
1 parent ac4960c commit 2df9be6
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 13 deletions.
10 changes: 5 additions & 5 deletions src/rules/consistent-type-specifier-style.js
@@ -1,5 +1,9 @@
import docsUrl from '../docsUrl';

function isComma(token) {
return token.type === 'Punctuator' && token.value === ',';
}

module.exports = {
meta: {
type: 'suggestion',
Expand All @@ -24,6 +28,7 @@ module.exports = {
return {
ImportDeclaration(node) {
if (node.importKind === 'value' || node.importKind == null) {
// top-level value / unknown is valid
return;
}

Expand Down Expand Up @@ -220,8 +225,3 @@ module.exports = {
};
},
};

function isComma(token) {
return token.type === 'Punctuator' && token.value === ',';
}

90 changes: 82 additions & 8 deletions tests/src/rules/consistent-type-specifier-style.js
Expand Up @@ -8,14 +8,88 @@ const COMMON_TESTS = {
//
// always valid
//
test({ code: "import Foo from 'Foo';" }),
test({ code: "import type Foo from 'Foo';" }),
test({ code: "import { Foo } from 'Foo';" }),
test({ code: "import { Foo as Bar } from 'Foo';" }),
test({ code: "import * as Foo from 'Foo';" }),
test({ code: "import 'Foo';" }),
test({ code: "import {} from 'Foo';" }),
test({ code: "import type {} from 'Foo';" }),
// prefer-inline
test({
code: "import Foo from 'Foo';",
options: ['prefer-inline'],
}),
test({
code: "import type Foo from 'Foo';",
options: ['prefer-inline'],
}),
test({
code: "import { Foo } from 'Foo';",
options: ['prefer-inline'],
}),
test({
code: "import { Foo as Bar } from 'Foo';",
options: ['prefer-inline'],
}),
test({
code: "import * as Foo from 'Foo';",
options: ['prefer-inline'],
}),
test({
code: "import 'Foo';",
options: ['prefer-inline'],
}),
test({
code: "import {} from 'Foo';",
options: ['prefer-inline'],
}),
test({
code: "import type {} from 'Foo';",
options: ['prefer-inline'],
}),
// prefer-top-level
test({
code: "import Foo from 'Foo';",
options: ['prefer-top-level'],
}),
test({
code: "import type Foo from 'Foo';",
options: ['prefer-top-level'],
}),
test({
code: "import { Foo } from 'Foo';",
options: ['prefer-top-level'],
}),
test({
code: "import { Foo as Bar } from 'Foo';",
options: ['prefer-top-level'],
}),
test({
code: "import * as Foo from 'Foo';",
options: ['prefer-top-level'],
}),
test({
code: "import 'Foo';",
options: ['prefer-top-level'],
}),
test({
code: "import {} from 'Foo';",
options: ['prefer-top-level'],
}),
test({
code: "import type {} from 'Foo';",
options: ['prefer-top-level'],
}),

//
// prefer-inline
//
{
code: "import { type Foo } from 'Foo';",
options: ['prefer-inline'],
},
{
code: "import { type Foo as Bar } from 'Foo';",
options: ['prefer-inline'],
},
{
code: "import { type Foo, type Bar, Baz, Bam } from 'Foo';",
options: ['prefer-inline'],
},

//
// prefer-top-level
Expand Down

0 comments on commit 2df9be6

Please sign in to comment.