Browse Source

feat(neon_lints): use lint_maker package

Signed-off-by: Nikolas Rimikis <leptopoda@users.noreply.github.com>
pull/690/head
Nikolas Rimikis 1 year ago
parent
commit
5b5dde0cd9
No known key found for this signature in database
GPG Key ID: 85ED1DE9786A4FF2
  1. 4
      packages/neon_lints/README.md
  2. 64
      packages/neon_lints/bin/neon_lints.dart
  3. 29
      packages/neon_lints/lint_maker.yaml
  4. 9
      packages/neon_lints/pubspec.yaml

4
packages/neon_lints/README.md

@ -1,8 +1,8 @@
A package containing a very strict set of linting rules. A package containing a very strict set of linting rules.
### Update 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 ```sh
fvm dart run bin/neon_lints.dart fvm dart run lint_maker
``` ```

64
packages/neon_lints/bin/neon_lints.dart

@ -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());
}

29
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'

9
packages/neon_lints/pubspec.yaml

@ -1,10 +1,13 @@
name: neon_lints name: neon_lints
description: Linting package used in the nextcloud-neon project description: Linting package used in the nextcloud-neon project
version: 1.0.0 version: 1.0.0
publish_to: none
environment: environment:
sdk: '>=3.1.0 <4.0.0' sdk: '>=3.1.0 <4.0.0'
dependencies: dev_dependencies:
http: ^1.1.0 lint_maker:
yaml: ^3.1.2 git:
url: https://github.com/Leptopoda/lint_maker
ref: 15bfdd3881bffc1516975368e86e6ec7d60aa991

Loading…
Cancel
Save