4 changed files with 37 additions and 69 deletions
			
			
		@ -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 | 
				
			||||
``` | 
				
			||||
 | 
				
			||||
					 | 
				
			||||
@ -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()); | 
				
			||||
} | 
				
			||||
@ -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' | 
				
			||||
@ -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 | 
				
			||||
					 | 
				
			||||
					Loading…
					
					
				
		Reference in new issue