Skip to content

Commit

Permalink
feat: close #249 @alagunoff turn on @typescript-eslint/consistent-typ…
Browse files Browse the repository at this point in the history
…e-imports
  • Loading branch information
xcatliu committed Aug 28, 2023
1 parent 7b536c4 commit 41cae59
Show file tree
Hide file tree
Showing 13 changed files with 27 additions and 13 deletions.
6 changes: 3 additions & 3 deletions config/rules/typescript.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,11 @@
},
"@typescript-eslint/consistent-type-imports": {
"name": "@typescript-eslint/consistent-type-imports",
"value": "off",
"value": "error",
"description": "必须使用 import type 导入类型",
"reason": "",
"badExample": "",
"goodExample": "",
"badExample": "<mark class=\"eslint-error\" data-tip=\"All imports in the declaration are only used as types. Use `import type`.&lt;br/&gt;&lt;span class='eslint-error-rule-id'&gt;eslint(@typescript-eslint/consistent-type-imports)&lt;/span&gt;\"><span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> Foo <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">'./FooType'</span><span class=\"token punctuation\">;</span></mark>\n<span class=\"token keyword\">const</span> x<span class=\"token punctuation\">:</span> Foo <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>",
"goodExample": "<span class=\"token keyword\">import</span> <span class=\"token keyword\">type</span> <span class=\"token punctuation\">{</span> Foo <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">'./FooType'</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> x<span class=\"token punctuation\">:</span> Foo <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>",
"fixable": true,
"extendsBaseRule": "",
"requiresTypeChecking": false
Expand Down
6 changes: 4 additions & 2 deletions scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import path from 'path';

import doctrine from 'doctrine';
import prettier from 'prettier';
import { ESLint, Linter } from 'eslint';
import type { Linter } from 'eslint';
import { ESLint } from 'eslint';
const eslintInstance = new ESLint({});
import insertTag from 'insert-tag';
import xmlEscape from 'xml-escape';

import { NAMESPACE_CONFIG, NAMESPACES, buildEslintrcMeta, Namespace, Rule, locale } from '../config';
import type { Namespace, Rule } from '../config';
import { NAMESPACE_CONFIG, NAMESPACES, buildEslintrcMeta, locale } from '../config';

import '../site/public/vendors/prism';
declare const Prism: any;
Expand Down
3 changes: 2 additions & 1 deletion site/components/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React, { useState, useEffect } from 'react';
import ReactTooltip from 'react-tooltip';

import { NAMESPACES, Namespace } from '../../config';
import type { Namespace } from '../../config';
import { NAMESPACES } from '../../config';
import { GitHubCorner } from './GitHubCorner';
import { RuleTable } from './RuleTable';
import { LanguageSwitch } from './LanguageSwitch';
Expand Down
6 changes: 4 additions & 2 deletions site/components/LanguageSwitch.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import React, { ReactElement } from 'react';
import type { ReactElement } from 'react';
import React from 'react';

import { newUrl } from '../utils';
import { languageOptions, Languages } from '../../config';
import type { Languages } from '../../config';
import { languageOptions } from '../../config';

interface LanguagesProps {
language: Languages;
Expand Down
3 changes: 2 additions & 1 deletion site/components/RuleTable.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';

import { NAMESPACE_CONFIG, Namespace, Rule } from '../../config';
import type { Namespace, Rule } from '../../config';
import { NAMESPACE_CONFIG } from '../../config';
import { parseDescription, t } from '../utils';

interface RuleTableProps {
Expand Down
3 changes: 2 additions & 1 deletion site/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import url from 'url';
import cookie from 'cookie';
import querystring from 'querystring';
import { locale, avaliableLanguages, Languages } from '../config';
import type { Languages } from '../config';
import { locale, avaliableLanguages } from '../config';

/**
* 解析描述或原因,转换 <, >, \n 等字符串
Expand Down
3 changes: 2 additions & 1 deletion test/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import path from 'path';
import assert from 'assert';
import eslint from 'eslint';
import { NAMESPACE_CONFIG, Namespace } from '../config';
import type { Namespace } from '../config';
import { NAMESPACE_CONFIG } from '../config';

const { ESLint } = eslint;
const eslintInstance = new ESLint({});
Expand Down
2 changes: 1 addition & 1 deletion test/typescript/consistent-type-imports/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ module.exports = {
/**
* 必须使用 import type 导入类型
*/
'@typescript-eslint/consistent-type-imports': 'off',
'@typescript-eslint/consistent-type-imports': 'error',
},
};
1 change: 1 addition & 0 deletions test/typescript/consistent-type-imports/FooType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type Foo = number;
2 changes: 2 additions & 0 deletions test/typescript/consistent-type-imports/bad.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { Foo } from './FooType';
const x: Foo = 1;
2 changes: 2 additions & 0 deletions test/typescript/consistent-type-imports/good.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import type { Foo } from './FooType';
const x: Foo = 1;
1 change: 1 addition & 0 deletions test/typescript/consistent-type-imports/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
2 changes: 1 addition & 1 deletion typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ module.exports = {
/**
* 必须使用 import type 导入类型
*/
'@typescript-eslint/consistent-type-imports': 'off',
'@typescript-eslint/consistent-type-imports': 'error',
/**
* 有默认值或可选的参数必须放到最后
*/
Expand Down

0 comments on commit 41cae59

Please sign in to comment.