Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions packages/custom_lint/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## Unreleased 0.7.0

- `custom_lint --fix` and the generated "Fix all <code>" assists
now correctly handle imports.
- Now supports a broad number of analyzer version.

## 0.6.10 - 2024-10-10

- Support installing custom_lint plugins in `dependencies:` instead of `dev_dependencies` (thanks to @dickermoshe).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import 'package:analyzer/error/error.dart' hide LintCode;
import 'package:analyzer/error/error.dart'
hide
// ignore: undefined_hidden_name, necessary to support lower analyzer versions
LintCode;
import 'package:analyzer/error/listener.dart';
import 'package:analyzer/source/source_range.dart';
import 'package:custom_lint_builder/custom_lint_builder.dart';
Expand Down
6 changes: 0 additions & 6 deletions packages/custom_lint/example/example_lint/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,3 @@ dependencies:

dev_dependencies:
custom_lint:

dependency_overrides:
custom_lint:
path: ../../../custom_lint
custom_lint_core:
path: ../../../custom_lint_core
8 changes: 0 additions & 8 deletions packages/custom_lint/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,3 @@ dev_dependencies:
custom_lint:
custom_lint_example_lint:
path: ./example_lint

dependency_overrides:
custom_lint:
path: ../../custom_lint
custom_lint_builder:
path: ../../custom_lint_builder
custom_lint_core:
path: ../../custom_lint_core
55 changes: 55 additions & 0 deletions packages/custom_lint/test/cli_process_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,61 @@ Analyzing...
expect(process.exitCode, 1);
});

test('Supports adding imports', () async {
final fixedPlugin = createPluginSource([
TestLintRule(
code: 'oy',
message: 'Oy',
onVariable: 'if (node.name.toString().endsWith("fixed")) return;',
fixes: [
TestLintFix(
name: 'OyFix',
dartBuilderCode: r'''
builder.importLibrary(Uri.parse('package:path/path.dart'));

builder.addSimpleReplacement(node.name.sourceRange, '${node.name}fixed');
''',
),
],
),
]);

final plugin = createPlugin(name: 'test_lint', main: fixedPlugin);

final app = createLintUsage(
name: 'test_app',
source: {
'lib/main.dart': '''
void fn() {}
void fn2() {}
''',
},
plugins: {'test_lint': plugin.uri},
);

final process = await Process.run(
'dart',
[customLintBinPath, '--fix'],
workingDirectory: app.path,
);

expect(trimDependencyOverridesWarning(process.stderr), isEmpty);

expect(app.file('lib', 'main.dart').readAsStringSync(), '''
import 'package:path/path.dart';

void fnfixed() {}
void fn2fixed() {}
''');

expect(process.stdout, '''
Analyzing...

No issues found!
''');
expect(process.exitCode, 0);
});

test('Can fix all lints', () async {
final plugin = createPlugin(name: 'test_lint', main: fixedPlugin);

Expand Down
5 changes: 4 additions & 1 deletion packages/custom_lint/test/cli_test.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import 'dart:convert';
import 'dart:io';

import 'package:analyzer/error/error.dart' hide LintCode;
import 'package:analyzer/error/error.dart'
hide
// ignore: undefined_hidden_name, Needed to support lower analyzer versions
LintCode;
import 'package:custom_lint/src/output/output_format.dart';
import 'package:test/test.dart';

Expand Down
20 changes: 17 additions & 3 deletions packages/custom_lint/test/create_project.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import 'dart:convert';
import 'dart:io';

import 'package:analyzer/error/error.dart' hide LintCode;
import 'package:analyzer/error/error.dart'
hide
// ignore: undefined_hidden_name, Needed to support lower analyzer versions
LintCode;
import 'package:path/path.dart';
import 'package:test/scaffolding.dart';

Expand Down Expand Up @@ -100,10 +103,13 @@ class TestLintFix {
TestLintFix({
required this.name,
this.nodeVisitor,
this.dartBuilderCode =
r"builder.addSimpleReplacement(node.name.sourceRange, '${node.name}fixed');",
});

final String name;
final String? nodeVisitor;
final String? dartBuilderCode;

void write(StringBuffer buffer, TestLintRule rule) {
buffer.write('''
Expand All @@ -124,9 +130,9 @@ class $name extends DartFix {
message: 'Fix ${rule.code}',
);

${nodeVisitor ?? r'''
${nodeVisitor ?? '''
changeBuilder.addDartFileEdit((builder) {
builder.addSimpleReplacement(node.name.sourceRange, '${node.name}fixed');
$dartBuilderCode
});
'''}
});
Expand Down Expand Up @@ -251,6 +257,14 @@ dev_dependencies:
custom_lint:
path: ${PeerProjectMeta.current.customLintPath}
${installAsDevDependency ? pluginDependencies : ""}

dependency_overrides:
custom_lint:
path: ${PeerProjectMeta.current.customLintPath}
custom_lint_core:
path: ${PeerProjectMeta.current.customLintCorePath}
custom_lint_builder:
path: ${PeerProjectMeta.current.customLintBuilderPath}
''',
packageConfig: createPackageConfig(
plugins: {...plugins, ...extraPackageConfig},
Expand Down
32 changes: 7 additions & 25 deletions packages/custom_lint/test/fixes_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ final multiChangeFixPlugin = createPluginSource([
),
]);

const ignoreId = '<<ignore>>';

void main() {
test('Can emit fixes', () async {
final plugin = createPlugin(
Expand Down Expand Up @@ -89,11 +91,7 @@ void fn2() {}
[await fixes, await fixes2]
.expand((e) => e.fixes)
.expand((e) => e.fixes)
.where(
(e) =>
e.change.id != 'ignore_for_file' &&
e.change.id != 'ignore_for_line',
),
.where((e) => e.change.id != ignoreId),
sources: ({'**/*': mainSource}, relativePath: app.path),
file: Directory.current.file(
'test',
Expand Down Expand Up @@ -125,11 +123,7 @@ void fn() {}
final fixes = await runner.getFixes(mainPath, 6);

expectMatchesGoldenFixes(
fixes.fixes.expand((e) => e.fixes).where(
(e) =>
e.change.id != 'ignore_for_file' &&
e.change.id != 'ignore_for_line',
),
fixes.fixes.expand((e) => e.fixes).where((e) => e.change.id != ignoreId),
sources: ({'**/*': mainSource}, relativePath: app.path),
file: Directory.current.file(
'test',
Expand Down Expand Up @@ -169,11 +163,7 @@ void fn4() {}
final fixes = await runner.getFixes(mainPath, 6);

expectMatchesGoldenFixes(
fixes.fixes.expand((e) => e.fixes).where(
(e) =>
e.change.id != 'ignore_for_file' &&
e.change.id != 'ignore_for_line',
),
fixes.fixes.expand((e) => e.fixes).where((e) => e.change.id != ignoreId),
sources: ({'**/*': mainSource}, relativePath: app.path),
file: Directory.current.file(
'test',
Expand Down Expand Up @@ -211,11 +201,7 @@ void fn2() {}
[await fixes, await fixes2]
.expand((e) => e.fixes)
.expand((e) => e.fixes)
.where(
(e) =>
e.change.id != 'ignore_for_file' &&
e.change.id != 'ignore_for_line',
),
.where((e) => e.change.id != ignoreId),
sources: ({'**/*': mainSource}, relativePath: app.path),
file: Directory.current.file(
'test',
Expand Down Expand Up @@ -253,11 +239,7 @@ void fn2() {}
[await fixes, await fixes2]
.expand((e) => e.fixes)
.expand((e) => e.fixes)
.where(
(e) =>
e.change.id != 'ignore_for_file' &&
e.change.id != 'ignore_for_line',
),
.where((e) => e.change.id != ignoreId),
sources: ({'**/*': mainSource}, relativePath: app.path),
file: Directory.current.file(
'test',
Expand Down
3 changes: 0 additions & 3 deletions packages/custom_lint/test/goldens.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ String _encodePrioritizedSourceChanges(
for (final prioritizedSourceChange in changes) {
buffer.writeln('Message: `${prioritizedSourceChange.change.message}`');
buffer.writeln('Priority: ${prioritizedSourceChange.priority}');
if (prioritizedSourceChange.change.id != null) {
buffer.writeln('Id: `${prioritizedSourceChange.change.id}`');
}
if (prioritizedSourceChange.change.selection case final selection?) {
buffer.writeln(
'Selection: offset ${selection.offset} ; '
Expand Down
6 changes: 0 additions & 6 deletions packages/custom_lint/test/goldens/fixes/add_ignore.diff
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
Message: `Ignore "hello_world" for line`
Priority: 1
Id: `ignore_for_line`
Diff for file `lib/main.dart:1`:
```
- void fn() {}
Expand All @@ -12,7 +11,6 @@ void fn2() {}
---
Message: `Ignore "hello_world" for file`
Priority: 0
Id: `ignore_for_file`
Diff for file `lib/main.dart:1`:
```
- void fn() {}
Expand All @@ -24,7 +22,6 @@ void fn2() {}
---
Message: `Ignore "hello_world" for line`
Priority: 1
Id: `ignore_for_line`
Diff for file `lib/main.dart:3`:
```
void fn() {}
Expand All @@ -38,7 +35,6 @@ void fn() {}
---
Message: `Ignore "hello_world" for file`
Priority: 0
Id: `ignore_for_file`
Diff for file `lib/main.dart:1`:
```
- void fn() {}
Expand All @@ -50,7 +46,6 @@ void fn2() {}
---
Message: `Ignore "hello_world" for line`
Priority: 1
Id: `ignore_for_line`
Diff for file `lib/main.dart:5`:
```
void fn2() {}
Expand All @@ -62,7 +57,6 @@ void fn2() {}
---
Message: `Ignore "hello_world" for file`
Priority: 0
Id: `ignore_for_file`
Diff for file `lib/main.dart:1`:
```
- void fn() {}
Expand Down
2 changes: 0 additions & 2 deletions packages/custom_lint/test/goldens/fixes/update_ignore.diff
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
Message: `Ignore "hello_world" for line`
Priority: 1
Id: `ignore_for_line`
Diff for file `lib/main.dart:5`:
```

Expand All @@ -12,7 +11,6 @@ void fn2() {}
---
Message: `Ignore "hello_world" for file`
Priority: 0
Id: `ignore_for_file`
Diff for file `lib/main.dart:4`:
```
void fn() {}
Expand Down
8 changes: 4 additions & 4 deletions packages/custom_lint/test/goldens/ignore_quick_fix.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
}
],
"linkedEditGroups": [],
"id": "ignore_for_line"
"id": "<<ignore>>"
}
},
{
Expand All @@ -36,7 +36,7 @@
}
],
"linkedEditGroups": [],
"id": "ignore_for_file"
"id": "<<ignore>>"
}
},
{
Expand All @@ -56,7 +56,7 @@
}
],
"linkedEditGroups": [],
"id": "ignore_for_line"
"id": "<<ignore>>"
}
},
{
Expand All @@ -76,7 +76,7 @@
}
],
"linkedEditGroups": [],
"id": "ignore_for_file"
"id": "<<ignore>>"
}
}
]
6 changes: 6 additions & 0 deletions packages/custom_lint_builder/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## Unreleased 0.7.0

- `custom_lint --fix` and the generated "Fix all <code>" assists
now correctly handle imports.
- Now supports a broad number of analyzer version.

## 0.6.10 - 2024-10-10

- `custom_lint` upgraded to `0.6.10`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import 'package:analyzer/error/error.dart' hide LintCode;
import 'package:analyzer/error/error.dart'
hide
// ignore: undefined_hidden_name, Needed to support lower analyzer versions
LintCode;
import 'package:analyzer/error/listener.dart';
import 'package:analyzer/source/source_range.dart';
import 'package:custom_lint_builder/custom_lint_builder.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,3 @@ dependencies:
analyzer_plugin: ^0.11.2
custom_lint_builder:
path: ../../../custom_lint_builder

dependency_overrides:
custom_lint:
path: ../../../custom_lint
custom_lint_core:
path: ../../../custom_lint_core
8 changes: 0 additions & 8 deletions packages/custom_lint_builder/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,3 @@ dev_dependencies:
custom_lint:
custom_lint_builder_example_lint:
path: ./example_lint

dependency_overrides:
custom_lint:
path: ../../custom_lint
custom_lint_builder:
path: ../../custom_lint_builder
custom_lint_core:
path: ../../custom_lint_core
Loading
Loading