Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

cool linter

this is a custom linter package for dart/flutter code. it can set linter for exclude some of words. this words you can set in analysis_options.yaml by example below

usage

1. add dependency to pubspec.yaml

dev_dependencies:
  cool_linter: ^1.2.0 # last version of plugin

2. add configuration to analysis_options.yaml

analyzer:
  plugins:
    - cool_linter

cool_linter:
  extended_rules:
    - always_specify_stream_subscription
    - prefer_trailing_comma
  always_specify_types:
    - typed_literal
    - declared_identifier
    - set_or_map_literal
    - simple_formal_parameter
    - type_name
    - variable_declaration_list
  regexp_exclude:
    -
      pattern: colors
      hint: use colors from design system instead!
      severity: warning
    -
      pattern: test123{1}
      severity: error
  exclude_folders:
    - test/**
    - lib/ku/**
  1. always_specify_types linter:

always_specify_types
this rule is like dart core linter rule, but you can choose which of this subrules want to use:

  • typed_literal
  • declared_identifier
  • set_or_map_literal
  • simple_formal_parameter
  • type_name
  • variable_declaration_list

also you can choose exclude folders for this rule. see exclude_folders

  1. regexp_exclude linter:

  • pattern – regexp-pattern, for example: test123{1}, ^test123$ and others
  • severity – [optional parameter]. it is console information level. may be warning, info, error. default is warning
  • hint – [optional parameter]. it is console information sentence
  • exclude_folders – this folders linter will ignore. by default excluded folders are:
'.dart_tool/**',
'.vscode/**',
'packages/**',
'ios/**',
'macos/**',
'web/**',
'linux/**',
'windows/**',
'go/**',
  1. extended_rules. always_specify_stream_subscription linter:

always use streamsubscription for stream.listen();

correct:

final stream<string> stream2 = stream<string>.value('value');
final streamsubscription<string> sub = stream2.listen((_) {}); // ok

warning:

final stream<string> stream1 = stream<string>.value('value');
stream1.listen((string ttt) {}); // lint

attention!!!

you must restart your ide for starting plugin

3. cli

you can use linter as command line tool
dart bin/cool_linter_cli.dart analyze -tsc -d test/fix/result --regexp_path test/regexp/regexp_settings_cli.yaml

or using dart pub run

available options:

  • -d – folder to analyze
  • -f – fix issues. now only for prefer_trailing_comma rule
  • -t – use always_specify_types_rule rule
  • -s – use always_specify_stream_subscription rule
  • -c – use prefer_trailing_comma rule
  • -f – fix issues. now only for prefer_trailing_comma rule
  • --regexp_path – path to file with regexp settings

also you must specify --regexp_path parameter if you want to regexp analyzer.
example: --regexp_path <path to regexp settings .yaml file>

regexp_exclude:
  -
    pattern: colors
    hint: use colors from design system instead!
    severity: warning
  -
    pattern: stestclasss
    hint: dont use testclass
    severity: error
  -
    pattern: stestclass2s
    hint: dont use testclass2
    severity: info

screenshot

4. result

example of analysis_options.yaml

analyzer:
  plugins:
    - cool_linter

cool_linter:
  extended_rules:
    - always_specify_stream_subscription
    - prefer_trailing_comma
  always_specify_types:
    - typed_literal
    - declared_identifier
    - set_or_map_literal
    - simple_formal_parameter
    - type_name
    - variable_declaration_list
  regexp_exclude:
    -
      pattern: colors
      hint: use colors from design system instead!
      severity: warning
    -
      pattern: test123{1}
      severity: error
  exclude_folders:
    - test/**
    - lib/ku/**

linter1

linter2

linter3


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

Top