dart-code-checker / dart-code-metrics

Software analytics tool that helps developers analyse and improve software quality.
https://dcm.dev
Other
860 stars 265 forks source link

feat: add avoid-substring rule #1206

Closed lsaudon closed 1 year ago

lsaudon commented 1 year ago

Issue: #1201

Rule documentation

Replace s.substring(100,200) to s.characters.getRange(100,200).

As we know, using String.substring method will cause problems if you are having emojis in the string. 
There are many articles in the web, such as [substring does not support UTF-16](https://github.com/dart-lang/sdk/issues/35798).

Good example

s.characters.getRange(14, 15); 

Bad example

s.substring(14, 15); 
codecov[bot] commented 1 year ago

Codecov Report

Merging #1206 (9362821) into master (96001b5) will increase coverage by 0.03%. The diff coverage is 100.00%.

:exclamation: Current head 9362821 differs from pull request most recent head 0c6df2f. Consider uploading reports for the commit 0c6df2f to get more accurate results

@@            Coverage Diff             @@
##           master    #1206      +/-   ##
==========================================
+ Coverage   86.21%   86.24%   +0.03%     
==========================================
  Files         359      361       +2     
  Lines        8133     8152      +19     
==========================================
+ Hits         7012     7031      +19     
  Misses       1121     1121              
Impacted Files Coverage Δ
...c/analyzers/lint_analyzer/rules/rules_factory.dart 100.00% <ø> (ø)
...les_list/avoid_substring/avoid_substring_rule.dart 100.00% <100.00%> (ø)
...yzer/rules/rules_list/avoid_substring/visitor.dart 100.00% <100.00%> (ø)

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more