Skip to content

Commit 8b37dae

Browse files
authored
1 parent 621a39d commit 8b37dae

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+883
-355
lines changed

packages/custom_lint/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## Unreleased 0.7.0
2+
3+
- `custom_lint --fix` and the generated "Fix all <code>" assists
4+
now correctly handle imports.
5+
- Now supports a broad number of analyzer version.
6+
17
## 0.6.10 - 2024-10-10
28

39
- Support installing custom_lint plugins in `dependencies:` instead of `dev_dependencies` (thanks to @dickermoshe).

packages/custom_lint/example/example_lint/lib/custom_lint_example_lint.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import 'package:analyzer/error/error.dart' hide LintCode;
1+
import 'package:analyzer/error/error.dart'
2+
hide
3+
// ignore: undefined_hidden_name, necessary to support lower analyzer versions
4+
LintCode;
25
import 'package:analyzer/error/listener.dart';
36
import 'package:analyzer/source/source_range.dart';
47
import 'package:custom_lint_builder/custom_lint_builder.dart';

packages/custom_lint/example/example_lint/pubspec.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,3 @@ dependencies:
1212

1313
dev_dependencies:
1414
custom_lint:
15-
16-
dependency_overrides:
17-
custom_lint:
18-
path: ../../../custom_lint
19-
custom_lint_core:
20-
path: ../../../custom_lint_core

packages/custom_lint/example/pubspec.yaml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,3 @@ dev_dependencies:
1111
custom_lint:
1212
custom_lint_example_lint:
1313
path: ./example_lint
14-
15-
dependency_overrides:
16-
custom_lint:
17-
path: ../../custom_lint
18-
custom_lint_builder:
19-
path: ../../custom_lint_builder
20-
custom_lint_core:
21-
path: ../../custom_lint_core

packages/custom_lint/test/cli_process_test.dart

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,61 @@ Analyzing...
588588
expect(process.exitCode, 1);
589589
});
590590

591+
test('Supports adding imports', () async {
592+
final fixedPlugin = createPluginSource([
593+
TestLintRule(
594+
code: 'oy',
595+
message: 'Oy',
596+
onVariable: 'if (node.name.toString().endsWith("fixed")) return;',
597+
fixes: [
598+
TestLintFix(
599+
name: 'OyFix',
600+
dartBuilderCode: r'''
601+
builder.importLibrary(Uri.parse('package:path/path.dart'));
602+
603+
builder.addSimpleReplacement(node.name.sourceRange, '${node.name}fixed');
604+
''',
605+
),
606+
],
607+
),
608+
]);
609+
610+
final plugin = createPlugin(name: 'test_lint', main: fixedPlugin);
611+
612+
final app = createLintUsage(
613+
name: 'test_app',
614+
source: {
615+
'lib/main.dart': '''
616+
void fn() {}
617+
void fn2() {}
618+
''',
619+
},
620+
plugins: {'test_lint': plugin.uri},
621+
);
622+
623+
final process = await Process.run(
624+
'dart',
625+
[customLintBinPath, '--fix'],
626+
workingDirectory: app.path,
627+
);
628+
629+
expect(trimDependencyOverridesWarning(process.stderr), isEmpty);
630+
631+
expect(app.file('lib', 'main.dart').readAsStringSync(), '''
632+
import 'package:path/path.dart';
633+
634+
void fnfixed() {}
635+
void fn2fixed() {}
636+
''');
637+
638+
expect(process.stdout, '''
639+
Analyzing...
640+
641+
No issues found!
642+
''');
643+
expect(process.exitCode, 0);
644+
});
645+
591646
test('Can fix all lints', () async {
592647
final plugin = createPlugin(name: 'test_lint', main: fixedPlugin);
593648

packages/custom_lint/test/cli_test.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import 'dart:convert';
22
import 'dart:io';
33

4-
import 'package:analyzer/error/error.dart' hide LintCode;
4+
import 'package:analyzer/error/error.dart'
5+
hide
6+
// ignore: undefined_hidden_name, Needed to support lower analyzer versions
7+
LintCode;
58
import 'package:custom_lint/src/output/output_format.dart';
69
import 'package:test/test.dart';
710

packages/custom_lint/test/create_project.dart

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import 'dart:convert';
22
import 'dart:io';
33

4-
import 'package:analyzer/error/error.dart' hide LintCode;
4+
import 'package:analyzer/error/error.dart'
5+
hide
6+
// ignore: undefined_hidden_name, Needed to support lower analyzer versions
7+
LintCode;
58
import 'package:path/path.dart';
69
import 'package:test/scaffolding.dart';
710

@@ -100,10 +103,13 @@ class TestLintFix {
100103
TestLintFix({
101104
required this.name,
102105
this.nodeVisitor,
106+
this.dartBuilderCode =
107+
r"builder.addSimpleReplacement(node.name.sourceRange, '${node.name}fixed');",
103108
});
104109

105110
final String name;
106111
final String? nodeVisitor;
112+
final String? dartBuilderCode;
107113

108114
void write(StringBuffer buffer, TestLintRule rule) {
109115
buffer.write('''
@@ -124,9 +130,9 @@ class $name extends DartFix {
124130
message: 'Fix ${rule.code}',
125131
);
126132
127-
${nodeVisitor ?? r'''
133+
${nodeVisitor ?? '''
128134
changeBuilder.addDartFileEdit((builder) {
129-
builder.addSimpleReplacement(node.name.sourceRange, '${node.name}fixed');
135+
$dartBuilderCode
130136
});
131137
'''}
132138
});
@@ -251,6 +257,14 @@ dev_dependencies:
251257
custom_lint:
252258
path: ${PeerProjectMeta.current.customLintPath}
253259
${installAsDevDependency ? pluginDependencies : ""}
260+
261+
dependency_overrides:
262+
custom_lint:
263+
path: ${PeerProjectMeta.current.customLintPath}
264+
custom_lint_core:
265+
path: ${PeerProjectMeta.current.customLintCorePath}
266+
custom_lint_builder:
267+
path: ${PeerProjectMeta.current.customLintBuilderPath}
254268
''',
255269
packageConfig: createPackageConfig(
256270
plugins: {...plugins, ...extraPackageConfig},

packages/custom_lint/test/fixes_test.dart

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ final multiChangeFixPlugin = createPluginSource([
5858
),
5959
]);
6060

61+
const ignoreId = '<<ignore>>';
62+
6163
void main() {
6264
test('Can emit fixes', () async {
6365
final plugin = createPlugin(
@@ -89,11 +91,7 @@ void fn2() {}
8991
[await fixes, await fixes2]
9092
.expand((e) => e.fixes)
9193
.expand((e) => e.fixes)
92-
.where(
93-
(e) =>
94-
e.change.id != 'ignore_for_file' &&
95-
e.change.id != 'ignore_for_line',
96-
),
94+
.where((e) => e.change.id != ignoreId),
9795
sources: ({'**/*': mainSource}, relativePath: app.path),
9896
file: Directory.current.file(
9997
'test',
@@ -125,11 +123,7 @@ void fn() {}
125123
final fixes = await runner.getFixes(mainPath, 6);
126124

127125
expectMatchesGoldenFixes(
128-
fixes.fixes.expand((e) => e.fixes).where(
129-
(e) =>
130-
e.change.id != 'ignore_for_file' &&
131-
e.change.id != 'ignore_for_line',
132-
),
126+
fixes.fixes.expand((e) => e.fixes).where((e) => e.change.id != ignoreId),
133127
sources: ({'**/*': mainSource}, relativePath: app.path),
134128
file: Directory.current.file(
135129
'test',
@@ -169,11 +163,7 @@ void fn4() {}
169163
final fixes = await runner.getFixes(mainPath, 6);
170164

171165
expectMatchesGoldenFixes(
172-
fixes.fixes.expand((e) => e.fixes).where(
173-
(e) =>
174-
e.change.id != 'ignore_for_file' &&
175-
e.change.id != 'ignore_for_line',
176-
),
166+
fixes.fixes.expand((e) => e.fixes).where((e) => e.change.id != ignoreId),
177167
sources: ({'**/*': mainSource}, relativePath: app.path),
178168
file: Directory.current.file(
179169
'test',
@@ -211,11 +201,7 @@ void fn2() {}
211201
[await fixes, await fixes2]
212202
.expand((e) => e.fixes)
213203
.expand((e) => e.fixes)
214-
.where(
215-
(e) =>
216-
e.change.id != 'ignore_for_file' &&
217-
e.change.id != 'ignore_for_line',
218-
),
204+
.where((e) => e.change.id != ignoreId),
219205
sources: ({'**/*': mainSource}, relativePath: app.path),
220206
file: Directory.current.file(
221207
'test',
@@ -253,11 +239,7 @@ void fn2() {}
253239
[await fixes, await fixes2]
254240
.expand((e) => e.fixes)
255241
.expand((e) => e.fixes)
256-
.where(
257-
(e) =>
258-
e.change.id != 'ignore_for_file' &&
259-
e.change.id != 'ignore_for_line',
260-
),
242+
.where((e) => e.change.id != ignoreId),
261243
sources: ({'**/*': mainSource}, relativePath: app.path),
262244
file: Directory.current.file(
263245
'test',

packages/custom_lint/test/goldens.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@ String _encodePrioritizedSourceChanges(
5555
for (final prioritizedSourceChange in changes) {
5656
buffer.writeln('Message: `${prioritizedSourceChange.change.message}`');
5757
buffer.writeln('Priority: ${prioritizedSourceChange.priority}');
58-
if (prioritizedSourceChange.change.id != null) {
59-
buffer.writeln('Id: `${prioritizedSourceChange.change.id}`');
60-
}
6158
if (prioritizedSourceChange.change.selection case final selection?) {
6259
buffer.writeln(
6360
'Selection: offset ${selection.offset} ; '

packages/custom_lint/test/goldens/fixes/add_ignore.diff

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
Message: `Ignore "hello_world" for line`
22
Priority: 1
3-
Id: `ignore_for_line`
43
Diff for file `lib/main.dart:1`:
54
```
65
- void fn() {}
@@ -12,7 +11,6 @@ void fn2() {}
1211
---
1312
Message: `Ignore "hello_world" for file`
1413
Priority: 0
15-
Id: `ignore_for_file`
1614
Diff for file `lib/main.dart:1`:
1715
```
1816
- void fn() {}
@@ -24,7 +22,6 @@ void fn2() {}
2422
---
2523
Message: `Ignore "hello_world" for line`
2624
Priority: 1
27-
Id: `ignore_for_line`
2825
Diff for file `lib/main.dart:3`:
2926
```
3027
void fn() {}
@@ -38,7 +35,6 @@ void fn() {}
3835
---
3936
Message: `Ignore "hello_world" for file`
4037
Priority: 0
41-
Id: `ignore_for_file`
4238
Diff for file `lib/main.dart:1`:
4339
```
4440
- void fn() {}
@@ -50,7 +46,6 @@ void fn2() {}
5046
---
5147
Message: `Ignore "hello_world" for line`
5248
Priority: 1
53-
Id: `ignore_for_line`
5449
Diff for file `lib/main.dart:5`:
5550
```
5651
void fn2() {}
@@ -62,7 +57,6 @@ void fn2() {}
6257
---
6358
Message: `Ignore "hello_world" for file`
6459
Priority: 0
65-
Id: `ignore_for_file`
6660
Diff for file `lib/main.dart:1`:
6761
```
6862
- void fn() {}

packages/custom_lint/test/goldens/fixes/update_ignore.diff

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
Message: `Ignore "hello_world" for line`
22
Priority: 1
3-
Id: `ignore_for_line`
43
Diff for file `lib/main.dart:5`:
54
```
65

@@ -12,7 +11,6 @@ void fn2() {}
1211
---
1312
Message: `Ignore "hello_world" for file`
1413
Priority: 0
15-
Id: `ignore_for_file`
1614
Diff for file `lib/main.dart:4`:
1715
```
1816
void fn() {}

packages/custom_lint/test/goldens/ignore_quick_fix.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
}
1717
],
1818
"linkedEditGroups": [],
19-
"id": "ignore_for_line"
19+
"id": "<<ignore>>"
2020
}
2121
},
2222
{
@@ -36,7 +36,7 @@
3636
}
3737
],
3838
"linkedEditGroups": [],
39-
"id": "ignore_for_file"
39+
"id": "<<ignore>>"
4040
}
4141
},
4242
{
@@ -56,7 +56,7 @@
5656
}
5757
],
5858
"linkedEditGroups": [],
59-
"id": "ignore_for_line"
59+
"id": "<<ignore>>"
6060
}
6161
},
6262
{
@@ -76,7 +76,7 @@
7676
}
7777
],
7878
"linkedEditGroups": [],
79-
"id": "ignore_for_file"
79+
"id": "<<ignore>>"
8080
}
8181
}
8282
]

packages/custom_lint_builder/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## Unreleased 0.7.0
2+
3+
- `custom_lint --fix` and the generated "Fix all <code>" assists
4+
now correctly handle imports.
5+
- Now supports a broad number of analyzer version.
6+
17
## 0.6.10 - 2024-10-10
28

39
- `custom_lint` upgraded to `0.6.10`

packages/custom_lint_builder/example/example_lint/lib/custom_lint_builder_example_lint.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import 'package:analyzer/error/error.dart' hide LintCode;
1+
import 'package:analyzer/error/error.dart'
2+
hide
3+
// ignore: undefined_hidden_name, Needed to support lower analyzer versions
4+
LintCode;
25
import 'package:analyzer/error/listener.dart';
36
import 'package:analyzer/source/source_range.dart';
47
import 'package:custom_lint_builder/custom_lint_builder.dart';

packages/custom_lint_builder/example/example_lint/pubspec.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,3 @@ dependencies:
99
analyzer_plugin: ^0.11.2
1010
custom_lint_builder:
1111
path: ../../../custom_lint_builder
12-
13-
dependency_overrides:
14-
custom_lint:
15-
path: ../../../custom_lint
16-
custom_lint_core:
17-
path: ../../../custom_lint_core

packages/custom_lint_builder/example/pubspec.yaml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,3 @@ dev_dependencies:
1111
custom_lint:
1212
custom_lint_builder_example_lint:
1313
path: ./example_lint
14-
15-
dependency_overrides:
16-
custom_lint:
17-
path: ../../custom_lint
18-
custom_lint_builder:
19-
path: ../../custom_lint_builder
20-
custom_lint_core:
21-
path: ../../custom_lint_core

0 commit comments

Comments
 (0)