Giter Club home page Giter Club logo

cool_linter's Introduction

Pub Version Dart SDK Version Pub popularity

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 autofix ๐Ÿ’ช for:

  • prefer_trailing_comma
  • always_specify_types_rule

for this subrules: declared_identifier simple_formal_parameter variable_declaration_list

for others subrules feel free to provide me PRs

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: \sTestClass\s
    hint: Dont use TestClass
    severity: ERROR
  -
    pattern: \sTestClass2\s
    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/**

Screenshot Screenshot Screenshot

cool_linter's People

Contributors

jwinterday avatar rexios80 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

cool_linter's Issues

Incompatible with freezed v2

$ flutter pub get
Because cool_linter >=2.4.0 depends on freezed_annotation ^1.1.0 and companion depends on freezed_annotation ^2.0.3, cool_linter >=2.4.0 is forbidden.
So, because companion depends on cool_linter ^2.4.0, version solving failed.
Running "flutter pub get" in mobile...
pub get failed (1; So, because companion depends on cool_linter ^2.4.0, version solving failed.)

Modernizing the codebase

This package uses old dependencies making it hard to use in modern projects. Most notably, cool_linter uses analyzer v2 while the current version is v5. This issue is about bumping all dependencies to their newest constraints and releasing a new version.

I am willing to send such a PR, but I need assurance that something like that will be accepted so my work doesn't go to waste. I plan to bump all deps and set dart sdk version to 3.0. @jWinterDay what do you think?

Publish new version

Hi !

I was about to use the package for a project, however, couldn't install it because depends on analyzer: ^1.7.0 and we're using analyzer: ^2.6.0.

After checking pubspec.yaml seems that the package is ready to support analyzer: ^2.8.0 (since 2940fb9)

But since no new package release (since (9ebe662 I assume), can not leverage that change.

Could we publish a new version of the package, to be able to use analyzer ^2 versions?

Thanks !

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.