@inthedark/dxlint 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +84 -2
- package/bin/dxlint +15 -0
- package/bin/dxlint-linux-x64 +0 -0
- package/bin/dxlint-win32-x64.exe +0 -0
- package/package.json +40 -4
- package/rules/conventions.dx +34 -0
- package/rules/correctness.dx +33 -0
- package/rules/es-no-semi.dx +11 -0
- package/rules/format.dx +49 -0
- package/rules/recommended.dx +51 -0
- package/rules/suspicious.dx +31 -0
- package/rules/types.dx +21 -0
- package/std/c.dx +23 -0
- package/std/core/lines.dx +51 -0
- package/std/core/lists.dx +76 -0
- package/std/core.dx +30 -0
- package/std/css.dx +17 -0
- package/std/dx.dx +31 -0
- package/std/json.dx +104 -0
- package/std/markdown.dx +11 -0
- package/std/python.dx +21 -0
- package/std/rust/format.dx +316 -0
- package/std/rust.dx +34 -0
- package/std/toml.dx +19 -0
- package/std/ts/arithmetic.dx +87 -0
- package/std/ts/assertions.dx +477 -0
- package/std/ts/calls.dx +246 -0
- package/std/ts/comments.dx +10 -0
- package/std/ts/conditions.dx +531 -0
- package/std/ts/constants.dx +335 -0
- package/std/ts/deprecation.dx +185 -0
- package/std/ts/directives.dx +60 -0
- package/std/ts/effects.dx +219 -0
- package/std/ts/enums.dx +233 -0
- package/std/ts/expression-fixes.dx +67 -0
- package/std/ts/expressions.dx +270 -0
- package/std/ts/flow.dx +2 -0
- package/std/ts/format.dx +755 -0
- package/std/ts/globals.dx +106 -0
- package/std/ts/grammar.dx +488 -0
- package/std/ts/helpers.dx +102 -0
- package/std/ts/import-attributes.dx +88 -0
- package/std/ts/import-no-deprecated.dx +73 -0
- package/std/ts/indentation.dx +442 -0
- package/std/ts/jsx.dx +646 -0
- package/std/ts/layout/blocks.dx +281 -0
- package/std/ts/layout/calls.dx +79 -0
- package/std/ts/layout/expressions.dx +213 -0
- package/std/ts/layout/literals.dx +114 -0
- package/std/ts/layout/separators.dx +184 -0
- package/std/ts/layout/shared.dx +203 -0
- package/std/ts/layout/text.dx +142 -0
- package/std/ts/layout/types.dx +182 -0
- package/std/ts/layout.dx +9 -0
- package/std/ts/license.dx +54 -0
- package/std/ts/literal-text.dx +3 -0
- package/std/ts/literals.dx +95 -0
- package/std/ts/methods.dx +69 -0
- package/std/ts/modules.dx +268 -0
- package/std/ts/names.dx +348 -0
- package/std/ts/naming.dx +169 -0
- package/std/ts/narrowing.dx +96 -0
- package/std/ts/parentheses.dx +262 -0
- package/std/ts/precedence.dx +25 -0
- package/std/ts/problems/calls.dx +34 -0
- package/std/ts/problems/classes.dx +39 -0
- package/std/ts/problems/control-flow.dx +257 -0
- package/std/ts/problems/declarations.dx +67 -0
- package/std/ts/problems/duplicates.dx +70 -0
- package/std/ts/problems/expressions.dx +154 -0
- package/std/ts/problems/helpers.dx +22 -0
- package/std/ts/problems/imports.dx +43 -0
- package/std/ts/problems/non-null.dx +78 -0
- package/std/ts/problems/numeric-precision.dx +66 -0
- package/std/ts/problems/regexp.dx +66 -0
- package/std/ts/problems/statements.dx +36 -0
- package/std/ts/problems/typescript.dx +55 -0
- package/std/ts/problems/whitespace.dx +40 -0
- package/std/ts/problems.dx +20 -0
- package/std/ts/regex/checks.dx +249 -0
- package/std/ts/regex/findings.dx +209 -0
- package/std/ts/regex/grammar.dx +80 -0
- package/std/ts/regex/suggestions.dx +94 -0
- package/std/ts/regex/values.dx +378 -0
- package/std/ts/regex.dx +5 -0
- package/std/ts/restrictions/comments.dx +76 -0
- package/std/ts/restrictions.dx +811 -0
- package/std/ts/scopes.dx +68 -0
- package/std/ts/scoping/atomic.dx +40 -0
- package/std/ts/scoping/bindings.dx +126 -0
- package/std/ts/scoping/constness.dx +72 -0
- package/std/ts/scoping/globals.dx +52 -0
- package/std/ts/scoping/loops.dx +86 -0
- package/std/ts/scoping/member-uses.dx +111 -0
- package/std/ts/scoping/receivers.dx +107 -0
- package/std/ts/scoping/shadowing.dx +202 -0
- package/std/ts/scoping/usage.dx +393 -0
- package/std/ts/scoping.dx +842 -0
- package/std/ts/selectors.dx +10 -0
- package/std/ts/spreads.dx +97 -0
- package/std/ts/structure/declarations.dx +52 -0
- package/std/ts/structure/lines.dx +79 -0
- package/std/ts/structure/lists.dx +144 -0
- package/std/ts/structure/padding.dx +258 -0
- package/std/ts/structure.dx +963 -0
- package/std/ts/style/classes.dx +157 -0
- package/std/ts/style/comments.dx +75 -0
- package/std/ts/style/declarations.dx +82 -0
- package/std/ts/style/expressions.dx +125 -0
- package/std/ts/style/imports.dx +44 -0
- package/std/ts/style/ordering.dx +192 -0
- package/std/ts/style/returns.dx +152 -0
- package/std/ts/style/signatures.dx +308 -0
- package/std/ts/style/type-exports.dx +62 -0
- package/std/ts/style/type-imports.dx +166 -0
- package/std/ts/style/types.dx +474 -0
- package/std/ts/style.dx +29 -0
- package/std/ts/suggestions/accessors.dx +138 -0
- package/std/ts/suggestions/builtins.dx +110 -0
- package/std/ts/suggestions/comparisons.dx +41 -0
- package/std/ts/suggestions/computed-keys.dx +20 -0
- package/std/ts/suggestions/constructors.dx +54 -0
- package/std/ts/suggestions/control-flow.dx +204 -0
- package/std/ts/suggestions/curly.dx +124 -0
- package/std/ts/suggestions/directives.dx +79 -0
- package/std/ts/suggestions/errors.dx +106 -0
- package/std/ts/suggestions/expressions.dx +230 -0
- package/std/ts/suggestions/functions.dx +260 -0
- package/std/ts/suggestions/globals.dx +187 -0
- package/std/ts/suggestions/helpers.dx +17 -0
- package/std/ts/suggestions/object-shorthand.dx +148 -0
- package/std/ts/suggestions/object-spread.dx +96 -0
- package/std/ts/suggestions/regexp.dx +59 -0
- package/std/ts/suggestions/renames.dx +50 -0
- package/std/ts/suggestions/strings.dx +47 -0
- package/std/ts/suggestions/templates.dx +104 -0
- package/std/ts/suggestions.dx +24 -0
- package/std/ts/template-fixes.dx +22 -0
- package/std/ts/tokens.dx +124 -0
- package/std/ts/type-specifiers.dx +93 -0
- package/std/ts/typed/assignments.dx +154 -0
- package/std/ts/typed/awaitability.dx +157 -0
- package/std/ts/typed/boolean-comparisons.dx +82 -0
- package/std/ts/typed/defaults.dx +97 -0
- package/std/ts/typed/enum-consistency.dx +68 -0
- package/std/ts/typed/enums.dx +52 -0
- package/std/ts/typed/errors.dx +32 -0
- package/std/ts/typed/floating-promises.dx +147 -0
- package/std/ts/typed/for-in-arrays.dx +21 -0
- package/std/ts/typed/includes.dx +102 -0
- package/std/ts/typed/nullish-coalescing.dx +149 -0
- package/std/ts/typed/optional-chains.dx +317 -0
- package/std/ts/typed/promises.dx +205 -0
- package/std/ts/typed/qualifiers.dx +108 -0
- package/std/ts/typed/readonly-members.dx +159 -0
- package/std/ts/typed/readonly-parameters.dx +121 -0
- package/std/ts/typed/redundant-constituents.dx +171 -0
- package/std/ts/typed/regexp-exec.dx +79 -0
- package/std/ts/typed/rejection-handlers.dx +91 -0
- package/std/ts/typed/return-await.dx +116 -0
- package/std/ts/typed/return-this.dx +67 -0
- package/std/ts/typed/strict-void-return.dx +121 -0
- package/std/ts/typed/string-boundaries.dx +153 -0
- package/std/ts/typed/switches.dx +147 -0
- package/std/ts/typed/template-expressions.dx +127 -0
- package/std/ts/typed/template-values.dx +88 -0
- package/std/ts/typed/transfers.dx +106 -0
- package/std/ts/typed/type-arguments.dx +337 -0
- package/std/ts/typed/type-constituents.dx +143 -0
- package/std/ts/typed/type-conversions.dx +82 -0
- package/std/ts/typed/type-parameters.dx +280 -0
- package/std/ts/typed/unbound-method.dx +167 -0
- package/std/ts/typed/unsafe-calls.dx +73 -0
- package/std/ts/typed/unsafe-members.dx +36 -0
- package/std/ts/typed/void-expressions.dx +101 -0
- package/std/ts/typed.dx +585 -0
- package/std/ts/values/arguments.dx +13 -0
- package/std/ts/values/enums.dx +104 -0
- package/std/ts/values/inspection.dx +274 -0
- package/std/ts/values.dx +1217 -0
- package/std/ts.dx +77 -0
- package/std/whitespace.dx +37 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# .ts/helpers: helpers shared by the native TypeScript rule definitions.
|
|
2
|
+
|
|
3
|
+
# A plain identifier, nothing else (`x`, `$el`, not `a.b` or `f()`).
|
|
4
|
+
fn is_identifier(x) = re_test(x, /^[A-Za-z_$][\w$]*$/)
|
|
5
|
+
|
|
6
|
+
fn unparenthesised_node(n) = if n not ts_parenthesized then n else { value n; walk (current) if current is ts_parenthesized then current.expression.node else null; last }
|
|
7
|
+
fn outer_parenthesised_node(n) = { value n; walk (current) if current.parent is ts_parenthesized then current.parent.node else null; last }
|
|
8
|
+
|
|
9
|
+
fn function_uses_this(n) = {
|
|
10
|
+
value n.children.nodes
|
|
11
|
+
walk (current) when {
|
|
12
|
+
current is (ts_function, ts_static_block) then []
|
|
13
|
+
current is (ts_method, ts_class_property) then filter(current.children.nodes, child =>
|
|
14
|
+
child is (ts_method.key, ts_method.decorator, ts_class_property.key, ts_class_property.decorator))
|
|
15
|
+
else then current.children.nodes
|
|
16
|
+
}
|
|
17
|
+
any (current) current is ts_this
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
fn function_uses_arguments(n) = {
|
|
21
|
+
value n.body.node
|
|
22
|
+
walk (current) current.children.nodes
|
|
23
|
+
any (reference) reference is ts_identifier && ts_arguments_owner(reference) == n
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
fn function_head_site(n) = {
|
|
27
|
+
value outer: outer_parenthesised_node(n)
|
|
28
|
+
value member: when {
|
|
29
|
+
n is ts_method then n
|
|
30
|
+
outer.parent is (ts_property, ts_class_property) then outer.parent.node
|
|
31
|
+
else then null
|
|
32
|
+
}
|
|
33
|
+
value if member == null && n is ts_arrow then n.operator.node else {
|
|
34
|
+
value from: last(n.type_parameter.nodes).end_offset ?? n.name.end_offset ?? n.key.end_offset ?? n.offset
|
|
35
|
+
value until: first(n.parameter.nodes).offset ?? n.return_type.offset ?? n.body.offset ?? n.end_offset
|
|
36
|
+
value opening: first(overlapping(ts_open_paren, from, until))
|
|
37
|
+
value {
|
|
38
|
+
start: last(member.decorator.nodes).token_neighbours.after.start ?? member.offset ?? n.offset,
|
|
39
|
+
end: opening.offset ?? first(n.parameter.nodes).offset ?? n.body.offset
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
# Function-wide warnings identify the callable, not its body.
|
|
45
|
+
fn function_warning_site(n) = when {
|
|
46
|
+
n is ts_method then n.key.node
|
|
47
|
+
n.name != null then n.name.node
|
|
48
|
+
n.parent is (ts_property, ts_class_property) then n.parent.key.node
|
|
49
|
+
n is ts_arrow then n.operator.node
|
|
50
|
+
else then { start: n.first_token.start, end: n.first_token.end }
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
fn function_description(n) = {
|
|
54
|
+
value outer: outer_parenthesised_node(n)
|
|
55
|
+
value member: when {
|
|
56
|
+
n is ts_method then n
|
|
57
|
+
outer is (ts_property.value, ts_class_property.init) then outer.parent.node
|
|
58
|
+
else then null
|
|
59
|
+
}
|
|
60
|
+
value in_class: member is ts_class_property || member.parent is ts_class
|
|
61
|
+
value private: member.key is ts_private_name
|
|
62
|
+
value name: when {
|
|
63
|
+
private then member.key.identifier_name
|
|
64
|
+
member.static_name != null then "'" member.static_name "'"
|
|
65
|
+
member.key is (ts_string, ts_number) then member.key.text
|
|
66
|
+
member.key is ts_computed_key && unparenthesised_node(member.key.expression.node) is (ts_string, ts_number) then unparenthesised_node(member.key.expression.node).text
|
|
67
|
+
n is ts_function && n.name != null then "'" n.name.identifier_name "'"
|
|
68
|
+
else then ""
|
|
69
|
+
}
|
|
70
|
+
value static: if in_class && contains(member.modifier, "static") then "static " else ""
|
|
71
|
+
value hidden: if in_class && private then "private " else ""
|
|
72
|
+
value async: if contains(n.modifier, "async") then "async " else ""
|
|
73
|
+
value generator: if contains(n.modifier, "*") then "generator " else ""
|
|
74
|
+
value kind: when {
|
|
75
|
+
member != null then when {
|
|
76
|
+
member.kind == "get" then "getter"
|
|
77
|
+
member.kind == "set" then "setter"
|
|
78
|
+
else then "method"
|
|
79
|
+
}
|
|
80
|
+
n is ts_arrow then "arrow function"
|
|
81
|
+
else then "function"
|
|
82
|
+
}
|
|
83
|
+
value description: "{static}{hidden}{async}{generator}{kind}"
|
|
84
|
+
value if n is ts_method && in_class && !contains(member.modifier, "static") && member.key not ts_computed_key && member.static_name == "constructor" then "constructor"
|
|
85
|
+
else description (if name != "" then " " name else "")
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
define {
|
|
89
|
+
in ts_function, ts_arrow, ts_method let function_name function_description(node)
|
|
90
|
+
in ts_node let enclosing_function_name {
|
|
91
|
+
value owner: { value parent.node; walk (current) current.parent.node; find (current) current is (ts_function, ts_arrow, ts_method) }
|
|
92
|
+
value owner.function_name
|
|
93
|
+
}
|
|
94
|
+
in ts_import {
|
|
95
|
+
let import_named_open {
|
|
96
|
+
value overlapping(ts_open_brace, first_token.end, from.offset)
|
|
97
|
+
find (token) token.paired_token.end <= from.offset
|
|
98
|
+
}
|
|
99
|
+
let import_named_close import_named_open.paired_token
|
|
100
|
+
}
|
|
101
|
+
in ts_property_signature, ts_method_signature, ts_call_signature, ts_index_signature let member_terminal_token if contains([";", ","], token_neighbours.after.text) then token_neighbours.after else last_token
|
|
102
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# Regular import/export attribute syntax, shared by formatting rules.
|
|
2
|
+
import .ts/tokens
|
|
3
|
+
|
|
4
|
+
define {
|
|
5
|
+
in ts_import, ts_export layer ts_import_attributes match ts_import_attributes ts_import_attribute_string ts_import_attribute_gap* /\b(?:with|assert)/ ts_import_attribute_gap* open:/\{/ until close:/\}/ ts_import_attribute_gap* /;?\z/
|
|
6
|
+
in ts_import_attributes match ts_import_attribute_string /"(?:\\[\s\S]|[^"\\])*"|'(?:\\[\s\S]|[^'\\])*'/
|
|
7
|
+
in ts_import_attributes match ts_import_attribute_key /(?:[^\W\d]|\$)[\w$]*/ or ts_import_attribute_string
|
|
8
|
+
in ts_import_attributes match ts_import_attribute_comment /\/\*/ until /\*\// or /\/\/[^\n\r\u{2028}\u{2029}]*/
|
|
9
|
+
in ts_import_attributes match ts_import_attribute_gap /\s+/ or ts_import_attribute_comment
|
|
10
|
+
in ts_import_attributes match ts_import_attribute_colon /:/
|
|
11
|
+
in ts_import_attributes match ts_import_attribute_comma /,/
|
|
12
|
+
in ts_import_attributes match ts_import_attribute key:ts_import_attribute_key ts_import_attribute_gap* colon:ts_import_attribute_colon ts_import_attribute_gap* value:ts_import_attribute_string
|
|
13
|
+
|
|
14
|
+
group ts_token_query_node ts_import_attributes, ts_import_attribute, ts_import_attribute_string,
|
|
15
|
+
ts_import_attribute_key, ts_import_attribute_comment, ts_import_attribute_gap,
|
|
16
|
+
ts_import_attribute_colon, ts_import_attribute_comma
|
|
17
|
+
|
|
18
|
+
group core_list ts_import_attributes
|
|
19
|
+
group attribute_list_part ts_import_attribute, ts_import_attribute_comma, ts_import_attribute_comment
|
|
20
|
+
fn attribute_list_edge(item) = {
|
|
21
|
+
start: item.offset, end: item.end_offset, comment: item is ts_import_attribute_comment,
|
|
22
|
+
text: if item not ts_import_attribute_comment then item.text
|
|
23
|
+
else if starts_with(item.text, "/*") then { value tail: byte_len(item.text) - 2; value byte_slice(item.text, 2, tail) }
|
|
24
|
+
else slice(item.text, 2),
|
|
25
|
+
}
|
|
26
|
+
in ts_import_attribute let attribute_list_child_edges [attribute_list_edge(key.node), attribute_list_edge(value.node)]
|
|
27
|
+
in ts_import_attribute_comma, ts_import_attribute_comment let attribute_list_child_edges [attribute_list_edge(node)]
|
|
28
|
+
in ts_import_attribute_comment let attribute_list_outer containing(ts_import_attribute) == null
|
|
29
|
+
in ts_import_attributes let attribute_list_items descendants(ts_import_attribute)
|
|
30
|
+
in ts_import_attributes let attribute_list_parts {
|
|
31
|
+
value descendants(attribute_list_part)
|
|
32
|
+
filter (part) part not ts_import_attribute_comment || part.attribute_list_outer
|
|
33
|
+
}
|
|
34
|
+
in ts_import_attributes let attribute_list_edges {
|
|
35
|
+
value attribute_list_parts
|
|
36
|
+
fold ([]) (edges, part) edges part.attribute_list_child_edges
|
|
37
|
+
}
|
|
38
|
+
in ts_import_attributes let attribute_list_plain filter(attribute_list_edges, edge => !edge.comment)
|
|
39
|
+
in ts_import_attributes let attribute_list_open attribute_list_edge(open.node)
|
|
40
|
+
in ts_import_attributes let attribute_list_close attribute_list_edge(close.node)
|
|
41
|
+
in ts_import_attributes let attribute_list_first { value attribute_list_edges; first; nonempty } ?? attribute_list_close
|
|
42
|
+
in ts_import_attributes let attribute_list_last { value attribute_list_edges; last; nonempty } ?? attribute_list_open
|
|
43
|
+
in ts_import_attributes let attribute_list_context {
|
|
44
|
+
kind: "ImportAttributes", brackets: "{{}}", count: count(attribute_list_items),
|
|
45
|
+
single: !{ value byte_slice(source, open.offset, close.end_offset); re_test /[\n\r\u{2028}\u{2029}]/ },
|
|
46
|
+
node_single: !{ value containing(ts_import).text.nonempty ?? containing(ts_export).text; re_test /[\n\r\u{2028}\u{2029}]/ },
|
|
47
|
+
first_broken: count(attribute_list_items) > 0 && {
|
|
48
|
+
value first_offset: first(attribute_list_items).offset
|
|
49
|
+
value byte_slice(source, open.end_offset, first_offset)
|
|
50
|
+
re_test /[\n\r\u{2028}\u{2029}]/
|
|
51
|
+
},
|
|
52
|
+
empty_comments: count(attribute_list_edges) > 0,
|
|
53
|
+
}
|
|
54
|
+
in ts_import_attributes let attribute_list_spacing_pairs ([[attribute_list_open, attribute_list_first]]
|
|
55
|
+
(if count(attribute_list_edges) == 0 then [] else [[attribute_list_last, attribute_list_close]]))
|
|
56
|
+
in ts_import_attributes let attribute_list_wrapping_pairs (
|
|
57
|
+
[[attribute_list_open, { value attribute_list_plain; first; nonempty } ?? attribute_list_close]]
|
|
58
|
+
{
|
|
59
|
+
value attribute_list_items
|
|
60
|
+
slice 1
|
|
61
|
+
map (item) [
|
|
62
|
+
{ value attribute_list_plain; filter (edge) edge.end <= item.offset; last },
|
|
63
|
+
attribute_list_edge(item.key.node),
|
|
64
|
+
]
|
|
65
|
+
}
|
|
66
|
+
[[{ value attribute_list_plain; last; nonempty } ?? attribute_list_open, attribute_list_close]]
|
|
67
|
+
)
|
|
68
|
+
in ts_import_attributes let attribute_list_comments descendants(ts_import_attribute_comment)
|
|
69
|
+
in ts_import_attributes let core_list_layout (
|
|
70
|
+
map(attribute_list_spacing_pairs, pair => {
|
|
71
|
+
value before: first(pair)
|
|
72
|
+
value after: last(pair)
|
|
73
|
+
value core_list_site(source, attribute_list_context, "spacing", before, after, attribute_list_comments)
|
|
74
|
+
})
|
|
75
|
+
(if attribute_list_context.count > 0 then
|
|
76
|
+
map(attribute_list_wrapping_pairs, pair => {
|
|
77
|
+
value before: first(pair)
|
|
78
|
+
value after: last(pair)
|
|
79
|
+
value core_list_site(source, attribute_list_context, "wrapping", before, after, attribute_list_comments)
|
|
80
|
+
})
|
|
81
|
+
else
|
|
82
|
+
map(attribute_list_spacing_pairs, pair => {
|
|
83
|
+
value before: first(pair)
|
|
84
|
+
value after: last(pair)
|
|
85
|
+
value core_list_site(source, attribute_list_context, "empty_wrapping", before, after, attribute_list_comments)
|
|
86
|
+
}))
|
|
87
|
+
)
|
|
88
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# eslint-plugin-import's `import/no-deprecated`: deprecated exports, their
|
|
2
|
+
# imports, and the names those imports bind.
|
|
3
|
+
|
|
4
|
+
import .ts/deprecation
|
|
5
|
+
|
|
6
|
+
define {
|
|
7
|
+
|
|
8
|
+
fn import_message(tag) = "Deprecated" (if tag.reason == "" then "." else ": " tag.reason)
|
|
9
|
+
|
|
10
|
+
fn import_namespace_root(n) = last(walk([n], current =>
|
|
11
|
+
if current is (ts_member, ts_index) then current.object.node
|
|
12
|
+
else if current is (ts_parenthesized, ts_non_null) then current.expression.node else null))
|
|
13
|
+
fn import_namespace(n) = {
|
|
14
|
+
value root: import_namespace_root(n)
|
|
15
|
+
value binding: if root != null && root is ts_identifier then name_binding(root) else null
|
|
16
|
+
value if binding == null then false else binding.node is ts_import.namespace
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
# Found once per import, not once per use of the name it binds.
|
|
20
|
+
in ts_import_specifier let import_tag import_deprecation_tag(local.node ?? imported.node)
|
|
21
|
+
in ts_import let import_default_tag if default_import == null then null else import_deprecation_tag(default_import.node)
|
|
22
|
+
|
|
23
|
+
in ts_import_specifier rule es-import-no-deprecated:specifier {
|
|
24
|
+
when import_tag != null
|
|
25
|
+
warn import_message(import_tag)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
in ts_import.default_import rule es-import-no-deprecated:default {
|
|
29
|
+
when parent.import_default_tag != null
|
|
30
|
+
warn import_message(parent.import_default_tag)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
# The names this file's deprecated imports bind: only a use spelled as one
|
|
34
|
+
# of them resolves any further.
|
|
35
|
+
fn import_local_node(specifier) = specifier.local.node ?? specifier.imported.node
|
|
36
|
+
in ts_program let import_deprecated_names {
|
|
37
|
+
value descendants(ts_import_specifier)
|
|
38
|
+
filter (specifier) specifier.import_tag != null
|
|
39
|
+
map (specifier) import_local_node(specifier).text
|
|
40
|
+
}
|
|
41
|
+
in ts_program let import_deprecated_defaults {
|
|
42
|
+
value descendants(ts_import)
|
|
43
|
+
filter (item) item.import_default_tag != null
|
|
44
|
+
map (item) item.default_import.node.text
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
in ts_identifier rule es-import-no-deprecated:use {
|
|
48
|
+
when contains(ts_program.import_deprecated_names, text) || contains(ts_program.import_deprecated_defaults, text)
|
|
49
|
+
when resolved == "import"
|
|
50
|
+
when containing(ts_jsx_opening) == null && containing(ts_jsx_closing) == null
|
|
51
|
+
let declaration scope_declaration
|
|
52
|
+
let tag if declaration.parent is ts_import_specifier then declaration.parent.import_tag
|
|
53
|
+
else if declaration is ts_import.default_import then declaration.parent.import_default_tag else null
|
|
54
|
+
when tag != null
|
|
55
|
+
warn import_message(tag)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
in ts_program let import_namespace_names {
|
|
59
|
+
value descendants(ts_import)
|
|
60
|
+
filter (item) item.namespace != null
|
|
61
|
+
map (item) item.namespace.node.text
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
in ts_member.property rule es-import-no-deprecated:namespace {
|
|
65
|
+
when count(ts_program.import_namespace_names) > 0
|
|
66
|
+
when contains(ts_program.import_namespace_names, import_namespace_root(parent.node).text ?? "")
|
|
67
|
+
when import_namespace(parent.node)
|
|
68
|
+
let tag deprecation_reason(node)
|
|
69
|
+
when tag != null
|
|
70
|
+
warn import_message(tag)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
}
|