-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add more lint checks and fix them (#342)
- Loading branch information
Showing
83 changed files
with
884 additions
and
305 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time | ||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven | ||
|
||
# This workflow uses actions that are not certified by GitHub. | ||
# They are provided by a third-party and are governed by | ||
# separate terms of service, privacy policy, and support | ||
# documentation. | ||
|
||
name: Flutter Build Test Analyze | ||
|
||
defaults: | ||
run: | ||
working-directory: das_client | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} | ||
cancel-in-progress: true | ||
|
||
on: | ||
push: | ||
paths: | ||
- 'das_client/**' | ||
pull_request: | ||
paths: | ||
- 'das_client/**' | ||
branches: [ "main" ] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-java@v4 | ||
with: | ||
distribution: 'temurin' | ||
java-version: '17' | ||
- uses: subosito/flutter-action@v2 | ||
with: | ||
flutter-version: '3.24.3' | ||
- name: Prepare Flutter Build | ||
run: | | ||
flutter pub get | ||
flutter pub run build_runner build --delete-conflicting-outputs | ||
- run: flutter analyze | ||
- run: flutter pub run custom_lint | ||
- run: flutter test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import 'package:custom_lint_builder/custom_lint_builder.dart'; | ||
import 'package:das_custom_lints/dont_use_src_folder_imports.dart'; | ||
|
||
// Entrypoint of plugin | ||
PluginBase createPlugin() => _DasCustomLints(); | ||
|
||
// The class listing all the [LintRule]s and [Assist]s defined by our plugin | ||
class _DasCustomLints extends PluginBase { | ||
// Lint rules | ||
@override | ||
List<LintRule> getLintRules(CustomLintConfigs configs) => [DontUseSrcFolderImports()]; | ||
|
||
// Assists | ||
@override | ||
List<Assist> getAssists() => []; | ||
} |
56 changes: 56 additions & 0 deletions
56
das_client/das_custom_lints/lib/dont_use_src_folder_imports.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import 'package:analyzer/error/listener.dart'; | ||
import 'package:custom_lint_builder/custom_lint_builder.dart'; | ||
import 'package:analyzer/error/error.dart'; | ||
|
||
// Lint rule to use src folder imports | ||
class DontUseSrcFolderImports extends DartLintRule { | ||
const DontUseSrcFolderImports() : super(code: _code); | ||
|
||
// Lint rule metadata | ||
static const _code = LintCode( | ||
name: 'dont_use_src_folder_imports', | ||
problemMessage: 'Don\'t use source folder imports', | ||
errorSeverity: ErrorSeverity.ERROR, | ||
); | ||
|
||
// `run` is where you analyze a file and report lint errors | ||
// Invoked on a file automatically on every file edit | ||
@override | ||
void run( | ||
CustomLintResolver resolver, | ||
ErrorReporter reporter, | ||
CustomLintContext context, | ||
) { | ||
|
||
// A call back fn that runs on all import declarations in a file | ||
context.registry.addImportDirective((importDirective) { | ||
var importUri = importDirective.uri.stringValue; | ||
|
||
if (importUri == null || !importUri.contains('/src/')) return; | ||
|
||
var filePath = importDirective.element!.source.fullName; | ||
// ignore imports from outside the lib folder (mainly tests) | ||
if (!filePath.contains('/lib/')) return; | ||
|
||
importUri = importUri.substring(importUri.indexOf('/') + 1); | ||
filePath = filePath.substring(filePath.indexOf('/lib/') + 5); | ||
|
||
final importParts = importUri.split('/src/'); | ||
final fileParts = filePath.split('/src/'); | ||
|
||
// allow it if its part of the same package | ||
if (fileParts[0].startsWith(importParts[0])) return; | ||
|
||
// report a lint error with the `code` and the respective import directive | ||
reporter.atNode(importDirective, LintCode( | ||
name: _code.name, | ||
problemMessage: 'Don\'t use source folder imports for importing ${importDirective.uri.stringValue}', | ||
errorSeverity: ErrorSeverity.ERROR, | ||
)); | ||
}); | ||
} | ||
|
||
// Possible fixes for the lint error go here | ||
@override | ||
List<Fix> getFixes() => []; | ||
} |
Oops, something went wrong.