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

New typescript flow rule #2614

Draft
wants to merge 38 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
1830d7a
add debug command for new rule
azyzz228 Dec 5, 2022
5684be8
draft files for the rule, test, docs.
azyzz228 Dec 5, 2022
7d1ebbd
add 2 test cases for each option
azyzz228 Dec 5, 2022
6141499
add typescript-flow alpha version
azyzz228 Dec 5, 2022
daaf8aa
add test cases for single option none
azyzz228 Dec 7, 2022
50ce08e
add blank docs for new rule
azyzz228 Dec 7, 2022
3321565
change export map to include word 'type' as a key for namespace when …
azyzz228 Dec 7, 2022
8bf8556
add new schema, comments, and handle single config option when it is …
azyzz228 Dec 7, 2022
bb172d6
delete none option and its code
azyzz228 Dec 8, 2022
803dde0
refactor and finish fixer for strict separate optiop
azyzz228 Dec 11, 2022
74ba6d3
add namespace test cases to invalid strict separate
azyzz228 Dec 11, 2022
06705cc
add default type export
azyzz228 Dec 11, 2022
bf6063a
add valid cases for strict separate
azyzz228 Dec 11, 2022
4a6a9bc
finish strict separate option
azyzz228 Dec 11, 2022
08d9832
add strict inline with only import
azyzz228 Dec 11, 2022
4b5e577
add test cases for strict inline with only one import
azyzz228 Dec 11, 2022
8f7239d
add invalid default import test cases for inline option
azyzz228 Dec 13, 2022
7e5388c
add fixer for inline option with ImportDefault specifier
azyzz228 Dec 13, 2022
8c7ff3f
fix one failing test case in default rule
azyzz228 Dec 14, 2022
250a022
add more named import test cases for strict and inline options
azyzz228 Dec 14, 2022
a630161
remove unnecessary comments
azyzz228 Dec 14, 2022
366ac51
added comment check if inline import is supported
azyzz228 Dec 14, 2022
5f79ac6
add check for TS version support for inline type import
azyzz228 Dec 14, 2022
150af6f
add invalid test case with repeated import with namespace to inline o…
azyzz228 Dec 14, 2022
64757e8
add support for namespace in repeated source for inline option
azyzz228 Dec 14, 2022
e05f4c2
add new typescript flow to src/index
azyzz228 Dec 15, 2022
fe60ea1
fix default type import with inline option
azyzz228 Dec 31, 2022
944d967
add TSX file and export/import type cases for typescript flow
azyzz228 Dec 31, 2022
a8d9ba1
add error messages
azyzz228 Jan 8, 2023
051efd2
delete unnecessary comments
azyzz228 Jan 8, 2023
b42c4d5
add 2 default import type test cases
azyzz228 Jan 8, 2023
b4cc95a
add docs
azyzz228 Jan 8, 2023
97d2074
remove custom script
azyzz228 Jan 8, 2023
fc0c163
restore ExportMap to the version from main branch
azyzz228 Jan 8, 2023
c088081
refactor specifier cache loop to function for config = separate
azyzz228 Feb 1, 2023
accfa3a
refactor by adding function for every piece of logic
azyzz228 Feb 2, 2023
a6246b2
remove redundant comments
azyzz228 Feb 14, 2023
05c62b8
Merge branch 'import-js:main' into new-typescript-flow-rule
azyzz228 Sep 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
remove unnecessary comments
azyzz228 committed Dec 14, 2022
commit a63016102e0fe183f2e5a5541d3ac7a018eb7b25
32 changes: 5 additions & 27 deletions src/rules/typescript-flow.js
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ import docsUrl from '../docsUrl';
import debug from 'debug';
const log = debug('eslint-plugin-import/typescript-flow');

// comes from tests/src/utils file, TODO?: import directly from there
// comes from tests/src/utils file, TODO?: import directly from there, issue: too many layers of folders away
import typescriptPkg from 'typescript/package.json';
import semver from 'semver';

@@ -43,16 +43,7 @@ function processBodyStatement(importMap, node){
importMap.set(node.source.value, { specifiers, hasDefaultImport, hasInlineDefaultImport, hasNamespaceImport });
}

// It seems unfortunate to have a rule that is only useful for typescript, but perhaps a rule that detects your TS (or flow) version,
// and can be configured for an order of preferences - ie, between "types as separate import statements",
// "types mixed with values, but marked with a type modifier", you could prefer one over the other,
// and it would fall back to the next one if the preferred one wasn't supported, and if neither are supported, the rule would noop.

// 3 options of prefering importing types: none, separate, modifier.
// none => no use of word 'type' preferred.
// separate: types as separate import statements
// modifier: types mixed with values, but marked with a type modifier

// TODO: revert changes in ExportMap file.
module.exports = {
meta: {
type: 'suggestion', // Layout?
@@ -70,7 +61,7 @@ module.exports = {
'type': 'string',
'enum': ['separate', 'inline'],
},
'minItems': 1,
'minItems': 2,
'maxItems': 2,
'uniqueItems': true,
},
@@ -81,20 +72,11 @@ module.exports = {
],
}],
},
create(context) {
// if TS is < 3.8 => we can just name import it.

// works from typescript >= 3.8
// import type { Person, Cache } from "./foo"
// ImportDeclaration importKind = 'type', ImportSpecifier.importKind = 'value'

// works only on typescript >= 4.5
// import { type Person, Cache } from "./foo";
// ImportDeclaration importKind = 'value', ImportSpecifier.importKind = 'type'
create(context) {

// 3 cases: strict cases: separate, inline. 3rd case is array of preference. The only thing to check is if arr[0] === inline =>
// check if it can be supported. If not, fall back on separate.
// If arr[0] === separate => just do separate ? Then what is really a logic? Taking care of user worrying about TS version?
// If arr[0] === separate => just assume it is separate

const supportInlineTypeImport = tsVersionSatisfies('>=4.5'); // type modifiers (inline type import) were introduced in TS 4.5.
// get Rule options.
@@ -270,11 +252,7 @@ module.exports = {
},
});
}



}

},
};
},