From 5b5dde0cd9c93bbe53b3af78c377407acb77e8f0 Mon Sep 17 00:00:00 2001 From: Nikolas Rimikis Date: Sat, 2 Sep 2023 22:32:39 +0200 Subject: [PATCH] feat(neon_lints): use lint_maker package Signed-off-by: Nikolas Rimikis --- packages/neon_lints/README.md | 4 +- packages/neon_lints/bin/neon_lints.dart | 64 ------------------------- packages/neon_lints/lint_maker.yaml | 29 +++++++++++ packages/neon_lints/pubspec.yaml | 9 ++-- 4 files changed, 37 insertions(+), 69 deletions(-) delete mode 100644 packages/neon_lints/bin/neon_lints.dart create mode 100644 packages/neon_lints/lint_maker.yaml diff --git a/packages/neon_lints/README.md b/packages/neon_lints/README.md index 846963e0..971c86a4 100644 --- a/packages/neon_lints/README.md +++ b/packages/neon_lints/README.md @@ -1,8 +1,8 @@ A package containing a very strict set of linting rules. ### Update rules: -To update the rules you need to update the `commitHash` variable in [neon_lints.dart](bin/neon_lints.dart) and execute it by running: +To update the rules you need to update the `commitHash` in [lint_maker.yaml](lint_maker.yaml) and regenerate by running: ```sh -fvm dart run bin/neon_lints.dart +fvm dart run lint_maker ``` diff --git a/packages/neon_lints/bin/neon_lints.dart b/packages/neon_lints/bin/neon_lints.dart deleted file mode 100644 index 15a7e572..00000000 --- a/packages/neon_lints/bin/neon_lints.dart +++ /dev/null @@ -1,64 +0,0 @@ -import 'dart:io'; - -import 'package:http/http.dart' as http; -import 'package:yaml/yaml.dart'; - -/// Disabled rules. -/// -/// These rules will be added but disabled. -const disabledRules = [ - 'always_specify_types', - 'avoid_annotating_with_dynamic', - 'avoid_as', - 'avoid_catches_without_on_clauses', - 'avoid_catching_errors', - 'avoid_classes_with_only_static_members', - 'avoid_final_parameters', - 'avoid_print', - 'diagnostic_describe_all_properties', - 'lines_longer_than_80_chars', - 'no_default_cases', - 'one_member_abstracts', - 'prefer_double_quotes', - 'prefer_relative_imports', - 'unnecessary_final', -]; - -/// Rules that won't be added to the list. -/// -/// This is needed for rules not yet available in the current dart version. -const excludedRules = []; - -/// Commit hash to use to fetch the rules from upstream -const commitHash = '7f40f11'; - -Future main() async { - final uri = Uri.parse('https://raw.githubusercontent.com/dart-lang/linter/$commitHash/example/all.yaml'); - final result = await http.get(uri); - final document = loadYaml(result.body) as YamlMap; - final rules = (document['linter'] as YamlMap)['rules'] as YamlList; - - final buffer = StringBuffer(''' -analyzer: - language: - strict-casts: true - errors: - flutter_style_todos: ignore - todo: ignore - exclude: - - "**.g.dart" - - "**.mocks.dart" -linter: - rules: -'''); - - for (final line in rules) { - final excluded = excludedRules.contains(line); - if (!excluded) { - final disabled = disabledRules.contains(line); - buffer.writeln(' $line: ${!disabled}'); - } - } - - File('lib/dart.yaml').writeAsStringSync(buffer.toString()); -} diff --git a/packages/neon_lints/lint_maker.yaml b/packages/neon_lints/lint_maker.yaml new file mode 100644 index 00000000..bce60456 --- /dev/null +++ b/packages/neon_lints/lint_maker.yaml @@ -0,0 +1,29 @@ +dart: + commitHash: 0a567d0 + output: 'lib/dart.yaml' + disabledRules: + - always_specify_types + - avoid_annotating_with_dynamic + - avoid_as + - avoid_catches_without_on_clauses + - avoid_catching_errors + - avoid_classes_with_only_static_members + - avoid_final_parameters + - avoid_print + - diagnostic_describe_all_properties + - lines_longer_than_80_chars + - no_default_cases + - one_member_abstracts + - prefer_double_quotes + - prefer_relative_imports + - unnecessary_final + preset: + analyzer: + language: + strict-casts: true + errors: + flutter_style_todos: ignore + todo: ignore + exclude: + - '**.g.dart' + - '**.mocks.dart' diff --git a/packages/neon_lints/pubspec.yaml b/packages/neon_lints/pubspec.yaml index e103e315..7fecb2e8 100644 --- a/packages/neon_lints/pubspec.yaml +++ b/packages/neon_lints/pubspec.yaml @@ -1,10 +1,13 @@ name: neon_lints description: Linting package used in the nextcloud-neon project version: 1.0.0 +publish_to: none environment: sdk: '>=3.1.0 <4.0.0' -dependencies: - http: ^1.1.0 - yaml: ^3.1.2 +dev_dependencies: + lint_maker: + git: + url: https://github.com/Leptopoda/lint_maker + ref: 15bfdd3881bffc1516975368e86e6ec7d60aa991