@ttsc/lint 0.33.1 → 0.34.0
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/go.mod +2 -2
- package/linthost/ast_helpers.go +2 -2
- package/linthost/base_chain_walk_crosses_generic_boundary_test.go +3 -3
- package/linthost/check_observations.go +14 -14
- package/linthost/check_observations_retains_failed_program_and_raw_inputs_test.go +3 -2
- package/linthost/command_check_preserves_compiler_argument_cwd_test.go +2 -2
- package/linthost/comment_scan_handles_malformed_parser_recovery_test.go +2 -1
- package/linthost/comment_scan_uses_parser_lexical_ranges_across_source_modes_test.go +2 -1
- package/linthost/compile.go +5 -8
- package/linthost/config.go +4 -2
- package/linthost/config_loader_sources_escape_every_literal_percent_test.go +2 -1
- package/linthost/contributor_diagnostic_ranges_are_bounded_test.go +19 -19
- package/linthost/contributor_range_fix_bounds_diagnostic_independently_from_edit_test.go +2 -2
- package/linthost/contributor_report_related_reaches_finding_test.go +1 -1
- package/linthost/engine.go +1 -1
- package/linthost/engine_quarantines_panicking_rule_per_file_test.go +4 -4
- package/linthost/engine_run_parallel_matches_serial_finding_set_test.go +1 -1
- package/linthost/fix.go +1 -1
- package/linthost/helpers_test.go +5 -4
- package/linthost/host.go +130 -52
- package/linthost/imported_tsx_source_joins_the_read_scope_test.go +1 -1
- package/linthost/input_observation.go +24 -27
- package/linthost/invalid_contributor_range_cannot_panic_inline_directive_filtering_test.go +1 -1
- package/linthost/lint_corpus_filename_separators_share_materialized_source_identity_test.go +1 -1
- package/linthost/load_config_resolver_compact_globs_preserve_entry_policy_test.go +2 -2
- package/linthost/load_program_keeps_checker_pool_for_type_aware_rules_test.go +4 -4
- package/linthost/lsp.go +10 -5
- package/linthost/no_floating_promises_javascript_generic_defaults_test.go +1 -1
- package/linthost/no_floating_promises_rejects_inapplicable_generic_receiver_branches_test.go +1 -1
- package/linthost/project_engine.go +1 -1
- package/linthost/project_rule_sources_apply_only_global_ignores_test.go +1 -1
- package/linthost/project_rule_sources_include_imported_sibling_source_test.go +2 -2
- package/linthost/project_source_files_follow_tsconfig_selection_test.go +2 -2
- package/linthost/project_source_selection_preserves_explicit_bundled_roots_test.go +6 -5
- package/linthost/resident_whole_corpus_matches_cold_load_test.go +1 -1
- package/linthost/rules_boundaries.go +7 -7
- package/linthost/rules_boundaries_dependencies.go +9 -9
- package/linthost/rules_format_declaration_header.go +11 -4
- package/linthost/rules_gap.go +1 -1
- package/linthost/rules_jsdoc.go +1 -1
- package/linthost/rules_logic.go +2 -2
- package/linthost/rules_nextjs.go +1 -1
- package/linthost/rules_no_loop_func.go +4 -4
- package/linthost/rules_no_promise_executor_return.go +1 -1
- package/linthost/rules_promise.go +16 -16
- package/linthost/rules_react_perf.go +1 -1
- package/linthost/rules_react_refresh.go +2 -2
- package/linthost/rules_security.go +4 -4
- package/linthost/rules_storybook.go +1 -1
- package/linthost/rules_testing_library.go +1 -1
- package/linthost/rules_ts_no_base_to_string.go +1 -1
- package/linthost/rules_ts_no_deprecated.go +3 -3
- package/linthost/rules_ts_no_unnecessary_qualifier.go +4 -4
- package/linthost/rules_ts_no_unnecessary_type_arguments.go +2 -2
- package/linthost/rules_ts_no_unsafe_assignment.go +1 -1
- package/linthost/rules_ts_no_unsafe_enum_comparison.go +1 -1
- package/linthost/rules_ts_prefer_readonly.go +1 -1
- package/linthost/rules_ts_switch_exhaustiveness_check.go +2 -2
- package/linthost/rules_ts_unbound_method.go +1 -1
- package/linthost/rules_unicorn_consistent_destructuring.go +2 -2
- package/linthost/rules_unicorn_consistent_existence_index_check.go +2 -2
- package/linthost/rules_unicorn_consistent_function_scoping.go +7 -7
- package/linthost/rules_unicorn_filename_case.go +1 -1
- package/linthost/rules_unicorn_isolated_functions.go +3 -3
- package/linthost/rules_unicorn_no_typeof_undefined.go +1 -1
- package/linthost/rules_unicorn_no_unnecessary_polyfills.go +1 -1
- package/linthost/rules_unicorn_no_unused_properties.go +3 -3
- package/linthost/rules_unicorn_prefer_number_properties.go +1 -1
- package/linthost/rules_unicorn_prefer_simple_condition_first.go +1 -1
- package/linthost/rules_unicorn_prevent_abbreviations.go +7 -7
- package/linthost/rules_var.go +1 -1
- package/linthost/solid_helpers_test.go +1 -1
- package/linthost/type_alias_reference_node_uses_borrowed_builder_context_test.go +2 -2
- package/linthost/type_instantiation_mappers_reach_runtime_endpoints_test.go +3 -3
- package/linthost/user_source_files_exclude_imported_declarations_and_javascript_test.go +2 -2
- package/linthost/user_source_files_span_program_typescript_sources_test.go +1 -1
- package/linthost/windows_project_source_selection_preserves_physical_aliases_test.go +5 -4
- package/package.json +2 -2
|
@@ -239,7 +239,7 @@ func (e *Engine) projectSources(files []*shimast.SourceFile) []*shimast.SourceFi
|
|
|
239
239
|
if file == nil {
|
|
240
240
|
continue
|
|
241
241
|
}
|
|
242
|
-
if e != nil && e.config != nil && e.config.ResolveRules(file.FileName()).Ignored {
|
|
242
|
+
if e != nil && e.config != nil && e.config.ResolveRules(string(file.FileName())).Ignored {
|
|
243
243
|
continue
|
|
244
244
|
}
|
|
245
245
|
sources = append(sources, file)
|
|
@@ -34,7 +34,7 @@ func TestProjectRuleSourcesApplyOnlyGlobalIgnores(t *testing.T) {
|
|
|
34
34
|
name: name,
|
|
35
35
|
check: func(ctx *publicrule.ProjectContext) {
|
|
36
36
|
for _, source := range ctx.Sources {
|
|
37
|
-
observed = append(observed, filepath.Clean(source.FileName()))
|
|
37
|
+
observed = append(observed, filepath.Clean(string(source.FileName())))
|
|
38
38
|
}
|
|
39
39
|
},
|
|
40
40
|
})
|
|
@@ -24,8 +24,8 @@ func (r importedSourcePopulationRule) Check(ctx *publicrule.ProjectContext) {
|
|
|
24
24
|
if file == nil {
|
|
25
25
|
continue
|
|
26
26
|
}
|
|
27
|
-
*r.observed = append(*r.observed, filepath.Base(file.FileName()))
|
|
28
|
-
*r.paths = append(*r.paths, file.FileName())
|
|
27
|
+
*r.observed = append(*r.observed, filepath.Base(string(file.FileName())))
|
|
28
|
+
*r.paths = append(*r.paths, string(file.FileName()))
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
@@ -56,7 +56,7 @@ func TestProjectSourceFilesFollowTsconfigSelection(t *testing.T) {
|
|
|
56
56
|
defer prog.close()
|
|
57
57
|
imported := map[string]int{"src/extra.ts": 0, "src/data.json": 0}
|
|
58
58
|
for _, file := range prog.tsProgram.SourceFiles() {
|
|
59
|
-
name := filepath.ToSlash(filepath.Clean(file.FileName()))
|
|
59
|
+
name := filepath.ToSlash(filepath.Clean(string(file.FileName())))
|
|
60
60
|
for expected := range imported {
|
|
61
61
|
if name == filepath.ToSlash(filepath.Join(root, expected)) {
|
|
62
62
|
imported[expected]++
|
|
@@ -71,7 +71,7 @@ func TestProjectSourceFilesFollowTsconfigSelection(t *testing.T) {
|
|
|
71
71
|
|
|
72
72
|
names := make([]string, 0)
|
|
73
73
|
for _, file := range prog.projectSourceFiles() {
|
|
74
|
-
rel, err := filepath.Rel(root, file.FileName())
|
|
74
|
+
rel, err := filepath.Rel(root, string(file.FileName()))
|
|
75
75
|
if err != nil {
|
|
76
76
|
t.Fatal(err)
|
|
77
77
|
}
|
|
@@ -9,6 +9,7 @@ import (
|
|
|
9
9
|
"testing"
|
|
10
10
|
|
|
11
11
|
"github.com/microsoft/typescript-go/shim/bundled"
|
|
12
|
+
shimtspath "github.com/microsoft/typescript-go/shim/tspath"
|
|
12
13
|
)
|
|
13
14
|
|
|
14
15
|
// TestProjectSourceSelectionPreservesExplicitBundledRoots verifies that an
|
|
@@ -21,10 +22,10 @@ import (
|
|
|
21
22
|
// @evidence contracts/testing.md#execution-ownership This public Go unit requires embedded libraries and invokes both source projections and the writable guard in process over temporary config/source inputs, without an installed package, product subprocess or native build. Native noembed ownership belongs to the native source-selection units.
|
|
22
23
|
func TestProjectSourceSelectionPreservesExplicitBundledRoots(t *testing.T) {
|
|
23
24
|
root := t.TempDir()
|
|
24
|
-
library := bundled.LibPath()
|
|
25
|
+
library := shimtspath.ResolveFile(bundled.LibPath(), "lib.es5.d.ts")
|
|
25
26
|
config, err := json.Marshal(map[string]any{
|
|
26
27
|
"compilerOptions": map[string]any{"target": "ES2022", "strict": true},
|
|
27
|
-
"files": []string{"main.ts", library},
|
|
28
|
+
"files": []string{"main.ts", string(library)},
|
|
28
29
|
})
|
|
29
30
|
if err != nil {
|
|
30
31
|
t.Fatal(err)
|
|
@@ -39,7 +40,7 @@ func TestProjectSourceSelectionPreservesExplicitBundledRoots(t *testing.T) {
|
|
|
39
40
|
bundledFiles := 0
|
|
40
41
|
var excluded *Finding
|
|
41
42
|
for _, file := range prog.tsProgram.SourceFiles() {
|
|
42
|
-
if bundled.IsBundled(file.FileName()) {
|
|
43
|
+
if bundled.IsBundled(string(file.FileName())) {
|
|
43
44
|
bundledFiles++
|
|
44
45
|
if file.FileName() != library && excluded == nil {
|
|
45
46
|
excluded = &Finding{File: file}
|
|
@@ -56,10 +57,10 @@ func TestProjectSourceSelectionPreservesExplicitBundledRoots(t *testing.T) {
|
|
|
56
57
|
sources = prog.projectSourceFiles
|
|
57
58
|
}
|
|
58
59
|
for _, file := range sources() {
|
|
59
|
-
files = append(files, filepath.ToSlash(file.FileName()))
|
|
60
|
+
files = append(files, filepath.ToSlash(string(file.FileName())))
|
|
60
61
|
}
|
|
61
62
|
expectedMain := filepath.ToSlash(filepath.Join(root, "main.ts"))
|
|
62
|
-
if len(files) != 2 || !slices.Contains(files, expectedMain) || !slices.Contains(files, library) {
|
|
63
|
+
if len(files) != 2 || !slices.Contains(files, expectedMain) || !slices.Contains(files, string(library)) {
|
|
63
64
|
t.Errorf("%s source membership=%v, want main.ts and explicit %s", name, files, library)
|
|
64
65
|
}
|
|
65
66
|
}
|
|
@@ -137,7 +137,7 @@ func fingerprintFindings(findings []*Finding) []string {
|
|
|
137
137
|
}
|
|
138
138
|
name := ""
|
|
139
139
|
if finding.File != nil {
|
|
140
|
-
name = filepath.Base(finding.File.FileName())
|
|
140
|
+
name = filepath.Base(string(finding.File.FileName()))
|
|
141
141
|
}
|
|
142
142
|
out = append(out, finding.Rule+"|"+name+"|"+
|
|
143
143
|
strconv.Itoa(finding.Pos)+"|"+strconv.Itoa(finding.End)+"|"+finding.Message)
|
|
@@ -38,7 +38,7 @@ func (boundariesElementTypes) Check(ctx *Context, node *shimast.Node) {
|
|
|
38
38
|
if len(opts.Elements) == 0 {
|
|
39
39
|
return
|
|
40
40
|
}
|
|
41
|
-
source := classifyBoundaryFile(ctx.File.FileName(), opts.Elements)
|
|
41
|
+
source := classifyBoundaryFile(string(ctx.File.FileName()), opts.Elements)
|
|
42
42
|
if source == nil {
|
|
43
43
|
return
|
|
44
44
|
}
|
|
@@ -46,7 +46,7 @@ func (boundariesElementTypes) Check(ctx *Context, node *shimast.Node) {
|
|
|
46
46
|
if !dep.relative {
|
|
47
47
|
continue
|
|
48
48
|
}
|
|
49
|
-
targetPath, ok := resolveBoundaryImport(ctx.File.FileName(), dep.specifier)
|
|
49
|
+
targetPath, ok := resolveBoundaryImport(string(ctx.File.FileName()), dep.specifier)
|
|
50
50
|
if !ok {
|
|
51
51
|
continue
|
|
52
52
|
}
|
|
@@ -96,12 +96,12 @@ func (boundariesEntryPoint) Check(ctx *Context, node *shimast.Node) {
|
|
|
96
96
|
if len(opts.Elements) == 0 {
|
|
97
97
|
return
|
|
98
98
|
}
|
|
99
|
-
source := classifyBoundaryFile(ctx.File.FileName(), opts.Elements)
|
|
99
|
+
source := classifyBoundaryFile(string(ctx.File.FileName()), opts.Elements)
|
|
100
100
|
for _, dep := range collectBoundaryDependencies(node) {
|
|
101
101
|
if !dep.relative {
|
|
102
102
|
continue
|
|
103
103
|
}
|
|
104
|
-
targetPath, ok := resolveBoundaryImport(ctx.File.FileName(), dep.specifier)
|
|
104
|
+
targetPath, ok := resolveBoundaryImport(string(ctx.File.FileName()), dep.specifier)
|
|
105
105
|
if !ok {
|
|
106
106
|
continue
|
|
107
107
|
}
|
|
@@ -128,7 +128,7 @@ func (boundariesNoPrivate) Check(ctx *Context, node *shimast.Node) {
|
|
|
128
128
|
if len(opts.Elements) == 0 {
|
|
129
129
|
return
|
|
130
130
|
}
|
|
131
|
-
source := classifyBoundaryFile(ctx.File.FileName(), opts.Elements)
|
|
131
|
+
source := classifyBoundaryFile(string(ctx.File.FileName()), opts.Elements)
|
|
132
132
|
if source == nil {
|
|
133
133
|
return
|
|
134
134
|
}
|
|
@@ -136,7 +136,7 @@ func (boundariesNoPrivate) Check(ctx *Context, node *shimast.Node) {
|
|
|
136
136
|
if !dep.relative {
|
|
137
137
|
continue
|
|
138
138
|
}
|
|
139
|
-
targetPath, ok := resolveBoundaryImport(ctx.File.FileName(), dep.specifier)
|
|
139
|
+
targetPath, ok := resolveBoundaryImport(string(ctx.File.FileName()), dep.specifier)
|
|
140
140
|
if !ok {
|
|
141
141
|
continue
|
|
142
142
|
}
|
|
@@ -160,7 +160,7 @@ func (boundariesNoUnknown) Check(ctx *Context, node *shimast.Node) {
|
|
|
160
160
|
if !dep.relative {
|
|
161
161
|
continue
|
|
162
162
|
}
|
|
163
|
-
targetPath, ok := resolveBoundaryImport(ctx.File.FileName(), dep.specifier)
|
|
163
|
+
targetPath, ok := resolveBoundaryImport(string(ctx.File.FileName()), dep.specifier)
|
|
164
164
|
if !ok {
|
|
165
165
|
continue
|
|
166
166
|
}
|
|
@@ -107,7 +107,7 @@ func (boundariesDependencies) Check(ctx *Context, node *shimast.Node) {
|
|
|
107
107
|
if err != nil {
|
|
108
108
|
return
|
|
109
109
|
}
|
|
110
|
-
source := classifyBoundaryFile(ctx.File.FileName(), options.Elements)
|
|
110
|
+
source := classifyBoundaryFile(string(ctx.File.FileName()), options.Elements)
|
|
111
111
|
if source == nil {
|
|
112
112
|
return
|
|
113
113
|
}
|
|
@@ -595,12 +595,12 @@ func describeBoundaryDependency(
|
|
|
595
595
|
source *boundaryFile,
|
|
596
596
|
dependency boundaryDependency,
|
|
597
597
|
) boundaryDependenciesDescription {
|
|
598
|
-
from := boundaryDependenciesEntityFromFile(source, ctx.File.FileName(), "local")
|
|
598
|
+
from := boundaryDependenciesEntityFromFile(source, string(ctx.File.FileName()), "local")
|
|
599
599
|
resolvedPath, resolved := resolveBoundaryDependencyPath(ctx, dependency)
|
|
600
600
|
local := dependency.relative || (resolved && boundaryDependenciesProjectLocalPath(ctx.CurrentDirectory, resolvedPath))
|
|
601
601
|
if local {
|
|
602
602
|
if !resolved && dependency.relative {
|
|
603
|
-
resolvedPath = filepath.Clean(filepath.Join(filepath.Dir(ctx.File.FileName()), filepath.FromSlash(dependency.specifier)))
|
|
603
|
+
resolvedPath = filepath.Clean(filepath.Join(filepath.Dir(string(ctx.File.FileName())), filepath.FromSlash(dependency.specifier)))
|
|
604
604
|
}
|
|
605
605
|
target := classifyBoundaryFile(resolvedPath, options.Elements)
|
|
606
606
|
to := boundaryDependenciesEntityFromFile(target, resolvedPath, "local")
|
|
@@ -648,21 +648,21 @@ func boundaryDependenciesEntityFromFile(file *boundaryFile, path, origin string)
|
|
|
648
648
|
func resolveBoundaryDependencyPath(ctx *Context, dependency boundaryDependency) (string, bool) {
|
|
649
649
|
if ctx != nil && ctx.Checker != nil && dependency.node != nil {
|
|
650
650
|
symbol := ctx.Checker.GetSymbolAtLocation(dependency.node)
|
|
651
|
-
if symbol != nil && symbol
|
|
651
|
+
if symbol != nil && shimast.SymbolFlagsOf(symbol)&shimast.SymbolFlagsAlias != 0 {
|
|
652
652
|
symbol = ctx.Checker.GetAliasedSymbol(symbol)
|
|
653
653
|
}
|
|
654
654
|
if symbol != nil {
|
|
655
|
-
for _, declaration := range symbol
|
|
655
|
+
for _, declaration := range shimast.SymbolDeclarationsOf(symbol) {
|
|
656
656
|
source := sourceFileForBoundaryDeclaration(declaration)
|
|
657
657
|
if source == nil || source.FileName() == "" {
|
|
658
658
|
continue
|
|
659
659
|
}
|
|
660
|
-
return filepath.Clean(source.FileName()), true
|
|
660
|
+
return filepath.Clean(string(source.FileName())), true
|
|
661
661
|
}
|
|
662
662
|
}
|
|
663
663
|
}
|
|
664
664
|
if ctx != nil && ctx.File != nil {
|
|
665
|
-
return resolveBoundaryImport(ctx.File.FileName(), dependency.specifier)
|
|
665
|
+
return resolveBoundaryImport(string(ctx.File.FileName()), dependency.specifier)
|
|
666
666
|
}
|
|
667
667
|
return "", false
|
|
668
668
|
}
|
|
@@ -715,9 +715,9 @@ func boundaryDependenciesShadowedRequire(ctx *Context, dependency boundaryDepend
|
|
|
715
715
|
if symbol == nil {
|
|
716
716
|
return false
|
|
717
717
|
}
|
|
718
|
-
for _, declaration := range symbol
|
|
718
|
+
for _, declaration := range shimast.SymbolDeclarationsOf(symbol) {
|
|
719
719
|
source := sourceFileForBoundaryDeclaration(declaration)
|
|
720
|
-
if source != nil && boundaryDependenciesProjectLocalPath(ctx.CurrentDirectory, source.FileName()) {
|
|
720
|
+
if source != nil && boundaryDependenciesProjectLocalPath(ctx.CurrentDirectory, string(source.FileName())) {
|
|
721
721
|
return true
|
|
722
722
|
}
|
|
723
723
|
}
|
|
@@ -504,12 +504,19 @@ func singleGenericHeritageHeader(src, base, prefix string, typeParams, heritage
|
|
|
504
504
|
if typeNode == nil {
|
|
505
505
|
return "", false
|
|
506
506
|
}
|
|
507
|
-
|
|
508
|
-
|
|
507
|
+
// An interface's `extends` and a class's `implements` element is a type
|
|
508
|
+
// reference when it names an entity; other elements keep the expression form.
|
|
509
|
+
var typeArguments *shimast.NodeList
|
|
510
|
+
if typeNode.Kind == shimast.KindTypeReference {
|
|
511
|
+
typeArguments = typeNode.AsTypeReferenceNode().TypeArguments
|
|
512
|
+
} else if ewta := typeNode.AsExpressionWithTypeArguments(); ewta != nil {
|
|
513
|
+
typeArguments = ewta.TypeArguments
|
|
514
|
+
}
|
|
515
|
+
if typeArguments == nil || len(typeArguments.Nodes) < 2 {
|
|
509
516
|
return "", false
|
|
510
517
|
}
|
|
511
518
|
nameStart := shimscanner.SkipTrivia(src, typeNode.Pos())
|
|
512
|
-
ltPos := typeArgsStart(src,
|
|
519
|
+
ltPos := typeArgsStart(src, typeArguments)
|
|
513
520
|
if nameStart < 0 || ltPos <= nameStart {
|
|
514
521
|
return "", false
|
|
515
522
|
}
|
|
@@ -517,7 +524,7 @@ func singleGenericHeritageHeader(src, base, prefix string, typeParams, heritage
|
|
|
517
524
|
if strings.ContainsRune(typeName, '\n') {
|
|
518
525
|
return "", false
|
|
519
526
|
}
|
|
520
|
-
args, ok := nodeListTexts(src,
|
|
527
|
+
args, ok := nodeListTexts(src, typeArguments)
|
|
521
528
|
if !ok {
|
|
522
529
|
return "", false
|
|
523
530
|
}
|
package/linthost/rules_gap.go
CHANGED
|
@@ -210,7 +210,7 @@ func requiresGenericArrowDisambiguation(
|
|
|
210
210
|
}
|
|
211
211
|
requiresDisambiguation := ctx.File.ScriptKind == shimcore.ScriptKindTSX
|
|
212
212
|
if !requiresDisambiguation {
|
|
213
|
-
switch strings.ToLower(filepath.Ext(ctx.File.FileName())) {
|
|
213
|
+
switch strings.ToLower(filepath.Ext(string(ctx.File.FileName()))) {
|
|
214
214
|
case ".mts", ".cts":
|
|
215
215
|
requiresDisambiguation = true
|
|
216
216
|
}
|
package/linthost/rules_jsdoc.go
CHANGED
|
@@ -70,7 +70,7 @@ func (r jsdocLintRule) Visits() []shimast.Kind {
|
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
func (r jsdocLintRule) Check(ctx *Context, node *shimast.Node) {
|
|
73
|
-
if ctx == nil || ctx.File == nil || r.check == nil || !isTypeScriptSourceName(ctx.File.FileName()) {
|
|
73
|
+
if ctx == nil || ctx.File == nil || r.check == nil || !isTypeScriptSourceName(string(ctx.File.FileName())) {
|
|
74
74
|
return
|
|
75
75
|
}
|
|
76
76
|
src := ctx.File.Text()
|
package/linthost/rules_logic.go
CHANGED
|
@@ -84,7 +84,7 @@ func isGlobalBooleanConverter(ctx *Context, callee *shimast.Node) bool {
|
|
|
84
84
|
// Binding retains this file's own runtime declaration even when a duplicate
|
|
85
85
|
// global declaration is omitted from the checker's merged global symbol.
|
|
86
86
|
if ctx.File != nil {
|
|
87
|
-
if local := ctx.File.AsNode().Locals()["Boolean"]; local != nil && local
|
|
87
|
+
if local := ctx.File.AsNode().Locals()["Boolean"]; local != nil && shimast.SymbolFlagsOf(local)&shimast.SymbolFlagsValue != 0 {
|
|
88
88
|
return false
|
|
89
89
|
}
|
|
90
90
|
}
|
|
@@ -94,7 +94,7 @@ func isGlobalBooleanConverter(ctx *Context, callee *shimast.Node) bool {
|
|
|
94
94
|
ctx.Checker.GetMergedSymbol(resolved) != ctx.Checker.GetMergedSymbol(global) {
|
|
95
95
|
return false
|
|
96
96
|
}
|
|
97
|
-
for _, declaration := range ctx.Checker.GetMergedSymbol(resolved)
|
|
97
|
+
for _, declaration := range shimast.SymbolDeclarationsOf(ctx.Checker.GetMergedSymbol(resolved)) {
|
|
98
98
|
if declaration == nil {
|
|
99
99
|
continue
|
|
100
100
|
}
|
package/linthost/rules_nextjs.go
CHANGED
|
@@ -698,7 +698,7 @@ func nextjsFilePath(file *shimast.SourceFile) string {
|
|
|
698
698
|
if file == nil {
|
|
699
699
|
return ""
|
|
700
700
|
}
|
|
701
|
-
return filepath.ToSlash(file.FileName())
|
|
701
|
+
return filepath.ToSlash(string(file.FileName()))
|
|
702
702
|
}
|
|
703
703
|
|
|
704
704
|
func nextjsIsPagesFile(file *shimast.SourceFile) bool {
|
|
@@ -244,7 +244,7 @@ func (a *noLoopFuncAnalysis) isReferencedNamedIIFE(function *shimast.Node) bool
|
|
|
244
244
|
}
|
|
245
245
|
|
|
246
246
|
func (a *noLoopFuncAnalysis) symbolDeclaredInside(symbol *shimast.Symbol, function *shimast.Node) bool {
|
|
247
|
-
for _, declaration := range symbol
|
|
247
|
+
for _, declaration := range shimast.SymbolDeclarationsOf(symbol) {
|
|
248
248
|
if declaration != nil && declaration.Pos() >= function.Pos() && declaration.End() <= function.End() {
|
|
249
249
|
return true
|
|
250
250
|
}
|
|
@@ -280,9 +280,9 @@ func (a *noLoopFuncAnalysis) binding(symbol *shimast.Symbol) noLoopFuncBinding {
|
|
|
280
280
|
return binding
|
|
281
281
|
}
|
|
282
282
|
binding := noLoopFuncBinding{kind: noLoopFuncOtherBinding}
|
|
283
|
-
declarations := symbol
|
|
284
|
-
if symbol
|
|
285
|
-
declarations = append([]*shimast.Node{symbol
|
|
283
|
+
declarations := shimast.SymbolDeclarationsOf(symbol)
|
|
284
|
+
if shimast.SymbolValueDeclarationOf(symbol) != nil {
|
|
285
|
+
declarations = append([]*shimast.Node{shimast.SymbolValueDeclarationOf(symbol)}, declarations...)
|
|
286
286
|
}
|
|
287
287
|
for _, declaration := range declarations {
|
|
288
288
|
root := noLoopFuncRootVariableDeclaration(declaration)
|
|
@@ -75,7 +75,7 @@ func isGlobalPromiseConstructor(ctx *Context, callee *shimast.Node) bool {
|
|
|
75
75
|
if resolved != global {
|
|
76
76
|
return false
|
|
77
77
|
}
|
|
78
|
-
for _, declaration := range resolved
|
|
78
|
+
for _, declaration := range shimast.SymbolDeclarationsOf(resolved) {
|
|
79
79
|
if declaration != nil && shimast.GetSourceFileOfNode(declaration) == ctx.File &&
|
|
80
80
|
promiseDeclarationIntroducesValue(declaration) {
|
|
81
81
|
return false
|
|
@@ -389,7 +389,7 @@ func isCallableCallbackParameter(
|
|
|
389
389
|
if callbackType == nil {
|
|
390
390
|
return false
|
|
391
391
|
}
|
|
392
|
-
if declaration := parameter
|
|
392
|
+
if declaration := shimast.SymbolValueDeclarationOf(parameter); declaration != nil {
|
|
393
393
|
if parameterDeclaration := declaration.AsParameterDeclaration(); parameterDeclaration != nil && parameterDeclaration.DotDotDotToken != nil {
|
|
394
394
|
callbackType = checker.GetNumberIndexType(callbackType)
|
|
395
395
|
if callbackType == nil {
|
|
@@ -540,7 +540,7 @@ func isNativePromiseConstructorLikeSeen(
|
|
|
540
540
|
if symbol == nil {
|
|
541
541
|
return false
|
|
542
542
|
}
|
|
543
|
-
if symbol
|
|
543
|
+
if shimast.SymbolNameOf(symbol) == "PromiseConstructor" && checker.IsLibSymbolForHoverVerbosity(symbol) {
|
|
544
544
|
return true
|
|
545
545
|
}
|
|
546
546
|
declared := checker.GetDeclaredTypeOfSymbol(symbol)
|
|
@@ -1529,15 +1529,15 @@ func floatingPromiseCallableArgumentApplicability(
|
|
|
1529
1529
|
return floatingPromiseCallUncertain
|
|
1530
1530
|
}
|
|
1531
1531
|
for _, expectedProperty := range shimchecker.Checker_getPropertiesOfType(checker, expectedType) {
|
|
1532
|
-
expectedOptional := expectedProperty
|
|
1533
|
-
actualProperty := checker.GetPropertyOfType(actualType, expectedProperty
|
|
1532
|
+
expectedOptional := shimast.SymbolFlagsOf(expectedProperty)&shimast.SymbolFlagsOptional != 0
|
|
1533
|
+
actualProperty := checker.GetPropertyOfType(actualType, shimast.SymbolNameOf(expectedProperty))
|
|
1534
1534
|
if actualProperty == nil {
|
|
1535
1535
|
if expectedOptional {
|
|
1536
1536
|
continue
|
|
1537
1537
|
}
|
|
1538
1538
|
return floatingPromiseCallIncompatible
|
|
1539
1539
|
}
|
|
1540
|
-
if !expectedOptional && actualProperty
|
|
1540
|
+
if !expectedOptional && shimast.SymbolFlagsOf(actualProperty)&shimast.SymbolFlagsOptional != 0 {
|
|
1541
1541
|
return floatingPromiseCallIncompatible
|
|
1542
1542
|
}
|
|
1543
1543
|
if floatingPromiseSymbolHasNonPublicDeclaration(expectedProperty) ||
|
|
@@ -1672,10 +1672,10 @@ func floatingPromiseSymbolHasNonPublicDeclaration(symbol *shimast.Symbol) bool {
|
|
|
1672
1672
|
return declaration != nil &&
|
|
1673
1673
|
declaration.ModifierFlags()&(shimast.ModifierFlagsPrivate|shimast.ModifierFlagsProtected) != 0
|
|
1674
1674
|
}
|
|
1675
|
-
if hasNonPublicModifier(symbol
|
|
1675
|
+
if hasNonPublicModifier(shimast.SymbolValueDeclarationOf(symbol)) {
|
|
1676
1676
|
return true
|
|
1677
1677
|
}
|
|
1678
|
-
for _, declaration := range symbol
|
|
1678
|
+
for _, declaration := range shimast.SymbolDeclarationsOf(symbol) {
|
|
1679
1679
|
if hasNonPublicModifier(declaration) {
|
|
1680
1680
|
return true
|
|
1681
1681
|
}
|
|
@@ -2409,7 +2409,7 @@ func isNativePromiseInstanceLikeSeen(
|
|
|
2409
2409
|
if symbol == nil {
|
|
2410
2410
|
return false
|
|
2411
2411
|
}
|
|
2412
|
-
if symbol
|
|
2412
|
+
if shimast.SymbolNameOf(symbol) == "Promise" && checker.IsLibSymbolForHoverVerbosity(symbol) {
|
|
2413
2413
|
return true
|
|
2414
2414
|
}
|
|
2415
2415
|
declared := checker.GetDeclaredTypeOfSymbol(symbol)
|
|
@@ -2497,7 +2497,7 @@ func promiseValueNameAndSymbol(
|
|
|
2497
2497
|
}
|
|
2498
2498
|
}
|
|
2499
2499
|
symbol := checker.GetSymbolAtLocation(nameNode)
|
|
2500
|
-
if symbol != nil && symbol
|
|
2500
|
+
if symbol != nil && shimast.SymbolFlagsOf(symbol)&shimast.SymbolFlagsAlias != 0 {
|
|
2501
2501
|
symbol = checker.GetAliasedSymbol(symbol)
|
|
2502
2502
|
}
|
|
2503
2503
|
return staticName, symbol
|
|
@@ -2541,7 +2541,7 @@ func typeMatchesPromiseSpecifier(
|
|
|
2541
2541
|
if symbol == nil {
|
|
2542
2542
|
symbol = t.Symbol()
|
|
2543
2543
|
}
|
|
2544
|
-
if symbol != nil && symbol
|
|
2544
|
+
if symbol != nil && shimast.SymbolFlagsOf(symbol)&shimast.SymbolFlagsAlias != 0 {
|
|
2545
2545
|
symbol = ctx.Checker.GetAliasedSymbol(symbol)
|
|
2546
2546
|
}
|
|
2547
2547
|
if promiseSpecifierMatchesSymbol(ctx, specifier, "", symbol) {
|
|
@@ -2565,7 +2565,7 @@ func promiseSpecifierMatchesSymbol(
|
|
|
2565
2565
|
) bool {
|
|
2566
2566
|
symbolName := ""
|
|
2567
2567
|
if symbol != nil {
|
|
2568
|
-
symbolName = symbol
|
|
2568
|
+
symbolName = shimast.SymbolNameOf(symbol)
|
|
2569
2569
|
}
|
|
2570
2570
|
if !promiseSpecifierNameMatches(specifier.Names, staticName, symbolName) {
|
|
2571
2571
|
return false
|
|
@@ -2600,18 +2600,18 @@ func promiseSymbolDeclaredInFile(ctx *Context, symbol *shimast.Symbol, configure
|
|
|
2600
2600
|
if ctx == nil || ctx.File == nil || symbol == nil {
|
|
2601
2601
|
return false
|
|
2602
2602
|
}
|
|
2603
|
-
for _, declaration := range symbol
|
|
2603
|
+
for _, declaration := range shimast.SymbolDeclarationsOf(symbol) {
|
|
2604
2604
|
source := sourceFileForPromiseDeclaration(declaration)
|
|
2605
2605
|
if source == nil || ctx.Checker.IsLibSymbolForHoverVerbosity(symbol) {
|
|
2606
2606
|
continue
|
|
2607
2607
|
}
|
|
2608
2608
|
if configuredPath == "" {
|
|
2609
|
-
if ctx.CurrentDirectory == "" || promisePathWithin(ctx.CurrentDirectory, source.FileName()) {
|
|
2609
|
+
if ctx.CurrentDirectory == "" || promisePathWithin(ctx.CurrentDirectory, string(source.FileName())) {
|
|
2610
2610
|
return true
|
|
2611
2611
|
}
|
|
2612
2612
|
continue
|
|
2613
2613
|
}
|
|
2614
|
-
if promiseDeclarationPathMatches(ctx.CurrentDirectory, source.FileName(), configuredPath) {
|
|
2614
|
+
if promiseDeclarationPathMatches(ctx.CurrentDirectory, string(source.FileName()), configuredPath) {
|
|
2615
2615
|
return true
|
|
2616
2616
|
}
|
|
2617
2617
|
}
|
|
@@ -2652,7 +2652,7 @@ func promiseSymbolDeclaredInPackage(symbol *shimast.Symbol, packageName string)
|
|
|
2652
2652
|
typesName := strings.TrimPrefix(packageName, "@")
|
|
2653
2653
|
typesName = strings.Replace(typesName, "/", "__", 1)
|
|
2654
2654
|
typesPath := "/node_modules/@types/" + typesName + "/"
|
|
2655
|
-
for _, declaration := range symbol
|
|
2655
|
+
for _, declaration := range shimast.SymbolDeclarationsOf(symbol) {
|
|
2656
2656
|
for parent := declaration; parent != nil; parent = parent.Parent {
|
|
2657
2657
|
if parent.Kind == shimast.KindModuleDeclaration {
|
|
2658
2658
|
if name := parent.Name(); name != nil && stringLiteralText(name) == packageName {
|
|
@@ -2664,7 +2664,7 @@ func promiseSymbolDeclaredInPackage(symbol *shimast.Symbol, packageName string)
|
|
|
2664
2664
|
if source == nil {
|
|
2665
2665
|
break
|
|
2666
2666
|
}
|
|
2667
|
-
fileName := "/" + strings.TrimLeft(filepath.ToSlash(source.FileName()), "/")
|
|
2667
|
+
fileName := "/" + strings.TrimLeft(filepath.ToSlash(string(source.FileName())), "/")
|
|
2668
2668
|
if strings.Contains(fileName, packagePath) || strings.Contains(fileName, typesPath) {
|
|
2669
2669
|
return true
|
|
2670
2670
|
}
|
|
@@ -56,7 +56,7 @@ func reactPerfIsTSXFile(ctx *Context) bool {
|
|
|
56
56
|
if ctx == nil || ctx.File == nil {
|
|
57
57
|
return false
|
|
58
58
|
}
|
|
59
|
-
return strings.EqualFold(filepath.Ext(ctx.File.FileName()), ".tsx")
|
|
59
|
+
return strings.EqualFold(filepath.Ext(string(ctx.File.FileName())), ".tsx")
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
func reactPerfAttributeExpression(initializer *shimast.Node) *shimast.Node {
|
|
@@ -65,11 +65,11 @@ func (onlyExportComponents) Check(ctx *Context, node *shimast.Node) {
|
|
|
65
65
|
if err := ctx.DecodeOptions(&options); err != nil {
|
|
66
66
|
return
|
|
67
67
|
}
|
|
68
|
-
if !shouldScanReactRefreshFile(ctx.File.FileName(), options.CheckJS) {
|
|
68
|
+
if !shouldScanReactRefreshFile(string(ctx.File.FileName()), options.CheckJS) {
|
|
69
69
|
return
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
scan := newReactRefreshScan(ctx, options, reactRefreshRequiresReactImport(ctx.File.FileName(), options.CheckJS))
|
|
72
|
+
scan := newReactRefreshScan(ctx, options, reactRefreshRequiresReactImport(string(ctx.File.FileName()), options.CheckJS))
|
|
73
73
|
for _, stmt := range node.Statements() {
|
|
74
74
|
scan.handleStatement(stmt)
|
|
75
75
|
}
|
|
@@ -442,10 +442,10 @@ func securityValueBindingModule(ctx *Context, identifier *shimast.Node) string {
|
|
|
442
442
|
if target == nil {
|
|
443
443
|
return ""
|
|
444
444
|
}
|
|
445
|
-
if module := securityRequiredModuleFromDeclaration(target
|
|
445
|
+
if module := securityRequiredModuleFromDeclaration(shimast.SymbolValueDeclarationOf(target)); module != "" {
|
|
446
446
|
return module
|
|
447
447
|
}
|
|
448
|
-
for _, declaration := range target
|
|
448
|
+
for _, declaration := range shimast.SymbolDeclarationsOf(target) {
|
|
449
449
|
if module := securityRequiredModuleFromDeclaration(declaration); module != "" {
|
|
450
450
|
return module
|
|
451
451
|
}
|
|
@@ -545,10 +545,10 @@ func securitySymbolHasDeclarationInFile(symbol *shimast.Symbol, file *shimast.So
|
|
|
545
545
|
}
|
|
546
546
|
return false
|
|
547
547
|
}
|
|
548
|
-
if belongs(symbol
|
|
548
|
+
if belongs(shimast.SymbolValueDeclarationOf(symbol)) {
|
|
549
549
|
return true
|
|
550
550
|
}
|
|
551
|
-
for _, declaration := range symbol
|
|
551
|
+
for _, declaration := range shimast.SymbolDeclarationsOf(symbol) {
|
|
552
552
|
if belongs(declaration) {
|
|
553
553
|
return true
|
|
554
554
|
}
|
|
@@ -1361,7 +1361,7 @@ func storybookFindPackageJSON(file *shimast.SourceFile) string {
|
|
|
1361
1361
|
if file == nil {
|
|
1362
1362
|
return ""
|
|
1363
1363
|
}
|
|
1364
|
-
dir := filepath.Dir(file.FileName())
|
|
1364
|
+
dir := filepath.Dir(string(file.FileName()))
|
|
1365
1365
|
for {
|
|
1366
1366
|
candidate := filepath.Join(dir, "package.json")
|
|
1367
1367
|
if _, err := os.Stat(candidate); err == nil {
|
|
@@ -733,7 +733,7 @@ func (s *testingLibraryState) reportInconsistentDataTestIDs(ctx *Context) {
|
|
|
733
733
|
if err := ctx.DecodeOptions(&opts); err != nil || opts.TestIDPattern == "" {
|
|
734
734
|
return
|
|
735
735
|
}
|
|
736
|
-
pattern := strings.ReplaceAll(opts.TestIDPattern, "{fileName}", testingLibraryFileName(ctx.File.FileName()))
|
|
736
|
+
pattern := strings.ReplaceAll(opts.TestIDPattern, "{fileName}", testingLibraryFileName(string(ctx.File.FileName())))
|
|
737
737
|
re, err := regexp.Compile(pattern)
|
|
738
738
|
if err != nil {
|
|
739
739
|
return
|
|
@@ -180,7 +180,7 @@ func typeOverridesToString(checker *shimchecker.Checker, t *shimchecker.Type) bo
|
|
|
180
180
|
if prop == nil {
|
|
181
181
|
return false
|
|
182
182
|
}
|
|
183
|
-
for _, decl := range prop
|
|
183
|
+
for _, decl := range shimast.SymbolDeclarationsOf(prop) {
|
|
184
184
|
if decl == nil {
|
|
185
185
|
continue
|
|
186
186
|
}
|
|
@@ -80,7 +80,7 @@ func (noDeprecated) Check(ctx *Context, node *shimast.Node) {
|
|
|
80
80
|
}
|
|
81
81
|
name := identifierText(node)
|
|
82
82
|
if name == "" {
|
|
83
|
-
name = symbol
|
|
83
|
+
name = shimast.SymbolNameOf(symbol)
|
|
84
84
|
}
|
|
85
85
|
message := "`" + name + "` is deprecated."
|
|
86
86
|
if comment := jsdocDeprecatedComment(tag); comment != "" {
|
|
@@ -120,7 +120,7 @@ func noDeprecatedLocationIsDeclarationName(loc *shimast.Node, symbol *shimast.Sy
|
|
|
120
120
|
if loc == nil || symbol == nil {
|
|
121
121
|
return false
|
|
122
122
|
}
|
|
123
|
-
for _, decl := range symbol
|
|
123
|
+
for _, decl := range shimast.SymbolDeclarationsOf(symbol) {
|
|
124
124
|
if decl == nil {
|
|
125
125
|
continue
|
|
126
126
|
}
|
|
@@ -141,7 +141,7 @@ func findDeprecatedJSDocTag(symbol *shimast.Symbol) *shimast.Node {
|
|
|
141
141
|
if symbol == nil {
|
|
142
142
|
return nil
|
|
143
143
|
}
|
|
144
|
-
for _, decl := range symbol
|
|
144
|
+
for _, decl := range shimast.SymbolDeclarationsOf(symbol) {
|
|
145
145
|
if tag := deprecatedJSDocTagOnNodeOrAncestors(decl); tag != nil {
|
|
146
146
|
return tag
|
|
147
147
|
}
|
|
@@ -123,7 +123,7 @@ func noUnnecessaryQualifierIsUnnecessary(ctx *Context, node *shimast.Node, head
|
|
|
123
123
|
if accessedSymbol == nil {
|
|
124
124
|
return false
|
|
125
125
|
}
|
|
126
|
-
fromScope := noUnnecessaryQualifierSymbolInScope(ctx, head, accessedSymbol
|
|
126
|
+
fromScope := noUnnecessaryQualifierSymbolInScope(ctx, head, shimast.SymbolFlagsOf(accessedSymbol), identifierText(name))
|
|
127
127
|
if fromScope == nil {
|
|
128
128
|
return false
|
|
129
129
|
}
|
|
@@ -158,14 +158,14 @@ func noUnnecessaryQualifierSymbolIsNamespaceInScope(ctx *Context, enclosing []*s
|
|
|
158
158
|
if symbol == nil || depth > 16 {
|
|
159
159
|
return false
|
|
160
160
|
}
|
|
161
|
-
for _, decl := range symbol
|
|
161
|
+
for _, decl := range shimast.SymbolDeclarationsOf(symbol) {
|
|
162
162
|
for _, ns := range enclosing {
|
|
163
163
|
if decl == ns {
|
|
164
164
|
return true
|
|
165
165
|
}
|
|
166
166
|
}
|
|
167
167
|
}
|
|
168
|
-
if symbol
|
|
168
|
+
if shimast.SymbolFlagsOf(symbol)&shimast.SymbolFlagsAlias != 0 {
|
|
169
169
|
alias := ctx.Checker.GetAliasedSymbol(symbol)
|
|
170
170
|
if alias != nil && alias != symbol {
|
|
171
171
|
return noUnnecessaryQualifierSymbolIsNamespaceInScope(ctx, enclosing, alias, depth+1)
|
|
@@ -183,7 +183,7 @@ func noUnnecessaryQualifierSymbolInScope(ctx *Context, head *shimast.Node, flags
|
|
|
183
183
|
return nil
|
|
184
184
|
}
|
|
185
185
|
for _, symbol := range ctx.Checker.GetSymbolsInScope(head, flags) {
|
|
186
|
-
if symbol != nil && symbol
|
|
186
|
+
if symbol != nil && shimast.SymbolNameOf(symbol) == name {
|
|
187
187
|
return symbol
|
|
188
188
|
}
|
|
189
189
|
}
|
|
@@ -162,13 +162,13 @@ func noUnnecessaryTypeArgumentsResolveParameters(ctx *Context, node, nameNode *s
|
|
|
162
162
|
target = qn.Right
|
|
163
163
|
}
|
|
164
164
|
symbol := ctx.Checker.GetSymbolAtLocation(target)
|
|
165
|
-
if symbol != nil && symbol
|
|
165
|
+
if symbol != nil && shimast.SymbolFlagsOf(symbol)&shimast.SymbolFlagsAlias != 0 {
|
|
166
166
|
symbol = ctx.Checker.GetAliasedSymbol(symbol)
|
|
167
167
|
}
|
|
168
168
|
if symbol == nil {
|
|
169
169
|
return nil
|
|
170
170
|
}
|
|
171
|
-
for _, decl := range symbol
|
|
171
|
+
for _, decl := range shimast.SymbolDeclarationsOf(symbol) {
|
|
172
172
|
switch decl.Kind {
|
|
173
173
|
case shimast.KindClassDeclaration, shimast.KindClassExpression,
|
|
174
174
|
shimast.KindInterfaceDeclaration, shimast.KindTypeAliasDeclaration:
|
|
@@ -511,7 +511,7 @@ func noUnsafeAssignmentCheckObjectDestructure(
|
|
|
511
511
|
if symbol == nil {
|
|
512
512
|
continue
|
|
513
513
|
}
|
|
514
|
-
properties[symbol
|
|
514
|
+
properties[shimast.SymbolNameOf(symbol)] = shimchecker.Checker_getTypeOfSymbolAtLocation(
|
|
515
515
|
ctx.Checker,
|
|
516
516
|
symbol,
|
|
517
517
|
senderNode,
|
|
@@ -157,7 +157,7 @@ func noUnsafeEnumComparisonEnumDeclaration(t *shimchecker.Type) *shimast.Node {
|
|
|
157
157
|
if sym == nil {
|
|
158
158
|
return nil
|
|
159
159
|
}
|
|
160
|
-
for _, decl := range sym
|
|
160
|
+
for _, decl := range shimast.SymbolDeclarationsOf(sym) {
|
|
161
161
|
if decl == nil {
|
|
162
162
|
continue
|
|
163
163
|
}
|