Skip to content
This repository was archived by the owner on Mar 24, 2026. It is now read-only.
Closed
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
15 changes: 7 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ jobs:
channel:
- master
pub:
# TODO - uncomment this after the SDK bumps its dependencies
# - get
- get
- upgrade

steps:
Expand All @@ -36,16 +35,16 @@ jobs:
- name: Add pub cache bin to PATH
run: echo "$HOME/.pub-cache/bin" >> $GITHUB_PATH

- name: Add pub cache to PATH
run: echo "PUB_CACHE="$HOME/.pub-cache"" >> $GITHUB_ENV

- name: Add pubspec_overrides to the analyzer_plugin starter
run: "echo \"dependency_overrides:\n custom_lint:\n path: ${{github.workspace}}/packages/custom_lint\" > packages/custom_lint/tools/analyzer_plugin/pubspec_overrides.yaml"
- name: Add pub cache to env
run: echo "PUB_CACHE=\"$HOME/.pub-cache\"" >> $GITHUB_ENV

- run: dart pub global activate melos

- name: Install dependencies
run: melos exec -- "dart pub ${{ matrix.pub }}"
run: |
dart pub ${{ matrix.pub }}
cd packages/custom_lint/example/example_lint/ dart pub ${{ matrix.pub }}
cd ../../../custom_lint_builder/example/example_lint/ dart pub ${{ matrix.pub }}

- name: Check format
run: dart format --set-exit-if-changed .
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ To create a custom lint, you will need two things:
```dart
import 'package:analyzer/error/listener.dart';
import 'package:custom_lint_builder/custom_lint_builder.dart';

// This is the entrypoint of our custom linter
PluginBase createPlugin() => _ExampleLinter();

Expand All @@ -123,7 +123,7 @@ To create a custom lint, you will need two things:
@override
void run(
CustomLintResolver resolver,
ErrorReporter reporter,
DiagnosticReporter reporter,
CustomLintContext context,
) {
// Our lint will highlight all variable declarations with our custom warning.
Expand Down
6 changes: 0 additions & 6 deletions melos.yaml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class PreferFinalProviders extends DartLintRule {
void run(
// This object contains metadata about the analyzed file
CustomLintResolver resolver,
// ErrorReporter is for submitting lints. It contains utilities to specify
// DiagnosticReporter is for submitting lints. It contains utilities to specify
// where the lint should show-up.
ErrorReporter reporter,
// This contains various utilities, including tools for inspecting the content
Expand Down Expand Up @@ -93,7 +93,7 @@ class _MakeProviderFinalFix extends DartFix {
@override
void run(
CustomLintResolver resolver,
// Similar to ErrorReporter, ChangeReporter is an object used for submitting
// Similar to DiagnosticReporter, ChangeReporter is an object used for submitting
// edits within a Dart file.
ChangeReporter reporter,
CustomLintContext context,
Expand Down
4 changes: 2 additions & 2 deletions packages/custom_lint/example/example_lint/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ name: custom_lint_example_lint
publish_to: none

environment:
sdk: '>=3.0.0 <4.0.0'
sdk: ">=3.5.0 <4.0.0"

dependencies:
analyzer: ^7.5.0
analyzer: ^8.1.0
analyzer_plugin: ^0.13.0
custom_lint_builder:
path: ../../../custom_lint_builder
Expand Down

This file was deleted.

4 changes: 3 additions & 1 deletion packages/custom_lint/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ name: custom_lint_example_app
publish_to: none

environment:
sdk: '>=3.0.0 <4.0.0'
sdk: ">=3.5.0 <4.0.0"

resolution: workspace

dependencies:
riverpod: ^2.0.0
Expand Down
10 changes: 0 additions & 10 deletions packages/custom_lint/example/pubspec_overrides.yaml

This file was deleted.

6 changes: 4 additions & 2 deletions packages/custom_lint/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ repository: https://github.com/invertase/dart_custom_lint
issue_tracker: https://github.com/invertase/dart_custom_lint/issues

environment:
sdk: ">=3.0.0 <4.0.0"
sdk: ">=3.5.0 <4.0.0"

resolution: workspace

dependencies:
analyzer: ^7.5.0
analyzer: ^8.1.0
analyzer_plugin: ^0.13.0
args: ^2.3.1
async: ^2.9.0
Expand Down
4 changes: 0 additions & 4 deletions packages/custom_lint/pubspec_overrides.yaml

This file was deleted.

27 changes: 12 additions & 15 deletions packages/custom_lint/test/cli_test.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import 'dart:convert';
import 'dart:io';

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

Expand Down Expand Up @@ -315,7 +312,7 @@ Analyzing...
TestLintRule(
code: 'hello_world',
message: 'Hello world',
errorSeverity: ErrorSeverity.WARNING,
severity: DiagnosticSeverity.WARNING,
),
]),
);
Expand Down Expand Up @@ -439,7 +436,7 @@ lib/custom_lint_client.dart:18:26: Error: Undefined name 'createPlugin'.
allOf(
contains('''
[hello_world]
[hello_world]
[hello_world]
[hello_world] Hello
[hello_world] world
'''),
Expand Down Expand Up @@ -490,47 +487,47 @@ class _Lint extends DartLintRule {
@override
void run(
CustomLintResolver resolver,
ErrorReporter reporter,
DiagnosticReporter reporter,
CustomLintContext context,
) {
final line2 = resolver.lineInfo.getOffsetOfLine(1);
reporter.atOffset(
errorCode: const LintCode(name: 'x2', problemMessage: 'x2'),
diagnosticCode: const LintCode(name: 'x2', problemMessage: 'x2'),
offset: line2 + 1,
length: 1,
);
reporter.atOffset(
errorCode: const LintCode(name: 'a', problemMessage: 'a'),
diagnosticCode: const LintCode(name: 'a', problemMessage: 'a'),
offset: line2 + 1,
length: 1,
);
reporter.atOffset(
errorCode: const LintCode(name: 'x', problemMessage: 'x'),
diagnosticCode: const LintCode(name: 'x', problemMessage: 'x'),
offset: line2 + 1,
length: 1,
);
reporter.atOffset(
errorCode: const LintCode(name: 'y', problemMessage: 'y'),
diagnosticCode: const LintCode(name: 'y', problemMessage: 'y'),
offset: line2,
length: 1,
);
reporter.atOffset(
errorCode: const LintCode(name: 'z', problemMessage: 'z'),
diagnosticCode: const LintCode(name: 'z', problemMessage: 'z'),
offset: 0,
length: 1,
);
reporter.atOffset(
errorCode: const LintCode(name: 'w', problemMessage: 'w', errorSeverity: ErrorSeverity.WARNING),
diagnosticCode: const LintCode(name: 'w', problemMessage: 'w', severity: DiagnosticSeverity.WARNING),
offset: 0,
length: 1,
);
reporter.atOffset(
errorCode: const LintCode(name: 'e', problemMessage: 'e', errorSeverity: ErrorSeverity.ERROR),
diagnosticCode: const LintCode(name: 'e', problemMessage: 'e', severity: DiagnosticSeverity.ERROR),
offset: 0,
length: 1,
);
reporter.atOffset(
errorCode: const LintCode(name: 's', problemMessage: 's', errorSeverity: ErrorSeverity.ERROR),
diagnosticCode: const LintCode(name: 's', problemMessage: 's', severity: DiagnosticSeverity.ERROR),
offset: 1,
length: 2,
);
Expand Down
12 changes: 6 additions & 6 deletions packages/custom_lint/test/create_project.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class TestLintRule {
this.onVariable = '',
this.ruleMembers = '',
this.fixes = const [],
this.errorSeverity = ErrorSeverity.INFO,
this.severity = DiagnosticSeverity.INFO,
});

final String code;
Expand All @@ -44,7 +44,7 @@ class TestLintRule {
final String onVariable;
final String ruleMembers;
final List<TestLintFix> fixes;
final ErrorSeverity errorSeverity;
final DiagnosticSeverity severity;

void run(StringBuffer buffer) {
final fixesCode = fixes.isEmpty
Expand All @@ -64,7 +64,7 @@ class $code extends DartLintRule {
: super(
code: LintCode(name: '$code',
problemMessage: '$message',
errorSeverity: ErrorSeverity.${errorSeverity.displayName.toUpperCase()}),
severity: DiagnosticSeverity.${severity.displayName.toUpperCase()}),
);

$fixesCode
Expand All @@ -86,7 +86,7 @@ $ruleMembers
buffer.write(
'''
@override
void run(CustomLintResolver resolver, ErrorReporter reporter, CustomLintContext context) {
void run(CustomLintResolver resolver, DiagnosticReporter reporter, CustomLintContext context) {
$onRun
context.registry.addFunctionDeclaration((node) {
$onVariable
Expand Down Expand Up @@ -119,8 +119,8 @@ class $name extends DartFix {
CustomLintResolver resolver,
ChangeReporter reporter,
CustomLintContext context,
AnalysisError analysisError,
List<AnalysisError> others,
Diagnostic analysisError,
List<Diagnostic> others,
) {
context.registry.addFunctionDeclaration((node) {
if (!analysisError.sourceRange.intersects(node.sourceRange)) return;
Expand Down
3 changes: 2 additions & 1 deletion packages/custom_lint/test/goldens.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ String _encodePrioritizedSourceChanges(
final output = SourceEdit.applySequence(
source,
prioritizedSourceChange.change.edits
.expand((element) => element.edits),
.expand((element) => element.edits)
.toList(),
);

final outputLineInfo = LineInfo.fromContent(output);
Expand Down
10 changes: 3 additions & 7 deletions packages/custom_lint/tools/analyzer_plugin/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@ version: 0.8.0
publish_to: none

environment:
sdk: ">=3.0.0 <4.0.0"
sdk: ">=3.5.0 <4.0.0"

resolution: workspace

dependencies:
custom_lint: 0.8.0

# TODO: If you want to contribute to custom_lint, add a pubspec_overrides.yaml file
# in this folder, containing the following:
# dependency_overrides:
# custom_lint:
# path: /absolute/path/to/custom_lint/folder
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import 'package:analyzer/error/error.dart'
hide
// ignore: undefined_hidden_name, Needed to support lower analyzer versions
LintCode;
import 'package:analyzer/diagnostic/diagnostic.dart';
import 'package:analyzer/error/listener.dart';
import 'package:analyzer/source/source_range.dart';
import 'package:custom_lint_builder/custom_lint_builder.dart';
Expand Down Expand Up @@ -52,9 +49,9 @@ class PreferFinalProviders extends DartLintRule {
void run(
// This object contains metadata about the analyzed file
CustomLintResolver resolver,
// ErrorReporter is for submitting lints. It contains utilities to specify
// DiagnosticReporter is for submitting lints. It contains utilities to specify
// where the lint should show-up.
ErrorReporter reporter,
DiagnosticReporter reporter,
// This contains various utilities, including tools for inspecting the content
// of Dart files in an efficient manner.
CustomLintContext context,
Expand Down Expand Up @@ -93,16 +90,16 @@ class _MakeProviderFinalFix extends DartFix {
@override
void run(
CustomLintResolver resolver,
// Similar to ErrorReporter, ChangeReporter is an object used for submitting
// Similar to DiagnosticReporter, ChangeReporter is an object used for submitting
// edits within a Dart file.
ChangeReporter reporter,
CustomLintContext context,
// This is the warning that was emitted by our [LintRule] and which we are
// trying to fix.
AnalysisError analysisError,
Diagnostic analysisError,
// This is the other warnings in the same file defined by our [LintRule].
// Useful in case we want to offer a "fix all" option.
List<AnalysisError> others,
List<Diagnostic> others,
) {
// Using similar logic as in "PreferFinalProviders", we inspect the Dart file
// to search for variable declarations.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ name: custom_lint_builder_example_lint
publish_to: none

environment:
sdk: '>=3.0.0 <4.0.0'
sdk: ">=3.5.0 <4.0.0"

resolution: workspace

dependencies:
analyzer: ^7.5.0
analyzer: ^8.1.0
analyzer_plugin: ^0.13.0
custom_lint_builder:
path: ../../../custom_lint_builder

This file was deleted.

4 changes: 3 additions & 1 deletion packages/custom_lint_builder/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ name: custom_lint_builder_example_app
publish_to: none

environment:
sdk: '>=3.0.0 <4.0.0'
sdk: ">=3.5.0 <4.0.0"

resolution: workspace

dependencies:
riverpod: ^2.0.0
Expand Down
10 changes: 0 additions & 10 deletions packages/custom_lint_builder/example/pubspec_overrides.yaml

This file was deleted.

Loading