dart-code-checker / dart-code-metrics Goto Github PK
View Code? Open in Web Editor NEWSoftware analytics tool that helps developers analyse and improve software quality.
Home Page: https://dcm.dev
License: Other
Software analytics tool that helps developers analyse and improve software quality.
Home Page: https://dcm.dev
License: Other
Check args
for message with arguments
We should add ability to sort members alphabetically inside one group.
Also should add support for Angular view children/content children annotations.
Rules the analysis does not react to exclude section in the analysis_options.yaml file
It would be nice to have // ignore
support for number-of-methods, number-of-arguments, and other metrics.
Sometimes, metrics provide false-positive warning for cases, when large amount of arguments & methods is necessary. Example of large amount of arguments is Angular DI factory providers, which serves particular technical role, but might require large amount of arguments, because those arguments should be injected into constructor.
Please describe what the rule should do:
Validate settings block in analysis_options.yaml
If your rule is inspired by other please provide link to it:
What category of rule is this? (place an "X" next to just one item)
[ ] Warns about a potential error (problem)
[ ] Suggests an alternate way of doing something (suggestion)
[X] Other (please specify:) Warns about problems in plugin setting block
Provide 2-3 code examples that this rule will warn about (it will be better if you can provide both good and bad examples):
Are you willing to submit a pull request to implement this rule?
See: Lanza. Object-Oriented Metrics in Practice. Page 18.
A rule that issues a warning when class member is declared with Object type. Must not issue a warning when function/method argument has type Object or when type argument is Object.
The number of methods is the total number of methods or functions in a class. High number of methods indicates a high complexity of the class.
See: Lanza. Object-Oriented Metrics in Practice. Page 16.
Deprecated in #56
lib/src/analysis_options.dart
lib/src/metrics_analysis_recorder.dart
Hello,
It could be very useful to add an option like --set-exit-on-alarm
and --set-exit-on-warning
to allow this library to make a pipeline fail.
I'm talking about GitLab here, but I think that exit code are used in other CI tools to made them fail.
Issue a warning for unnecessary type assertions.
Bad:
final myList = <int>[1,2,3];
...
myList.whereType<int> ... // myList is known to contain ints, therefore type assertion is redundant
...
if (myList is List) ... // myList is known to be a List, therefore type check is redundant
Inspired by TSLint rule
We should migrate type name checking to DartType checking.
Please describe what the rule should do:
Detect a classes contains many fields/methods/lines of code.
If your rule is inspired by other please provide link to it:
What category of rule is this? (place an "X" next to just one item)
[ ] Warns about a potential error (problem)
[ ] Suggests an alternate way of doing something (suggestion)
[x] Other (please specify:) anti-pattern
Provide 2-3 code examples that this rule will warn about (it will be better if you can provide both good and bad examples):
Are you willing to submit a pull request to implement this rule?
Hello!
This is more of a question on analyzer_plugin and not directly related to this package – but the resources on analyzer_plugin are scarce.
I would love if you were able to answer this question for me:
I've forked this repository and added both a print
and File(...).writeAsString
in tools/analyzer_plugin/bin/plugin.dart
, but neither of them do anything (while the warnings do appear).
Ironically, I even removed the call to start
, but still get the warnings implemented by this package to appear – which is illogical.
It's as if the analyzer is using the version of dart_code_metrics
on pub rather than the local one – when I've changed the dependency on dart_code_metrics
in tools/analyzer_plugin/pubspec.yaml
to use the local version instead of the remote version.
I would appreciate some guidance in that area. Thanks in advance!
Pass non-existent or non-directory path to root-folder param and cli-tool will throw.
Please describe what the rule should do:
Should check for trailing comma for arguments, parameters, enum values and collections.
By default should warn in cases when items aren't on a single line.
Additionally should accept items count breakpoint config. For example, if breakpoint count is equal 2, then the rule should warn when items count is greater than or equal to the count or items aren't on a single line.
What category of rule is this? (place an "X" next to just one item)
[ ] Warns about a potential error (problem)
[X] Suggests an alternate way of doing something (suggestion)
[ ] Other (please specify:)
Provide 2-3 code examples that this rule will warn about (it will be better if you can provide both good and bad examples):
Without config:
Bad:
void firstFunction(String arg1, String arg2,
String arg3) {
return;
}
Good:
void firstFunction(
String arg1,
String arg2,
String arg3,
) {
return;
}
With given config:
- break_on: 2
Bad:
void firstFunction(String arg1, String arg2,
String arg3) {
return;
}
void secondFunction(String arg1, String arg2, String arg3) {
return;
}
Good:
void firstFunction(
String arg1,
String arg2,
String arg3,
) {
return;
}
void secondFunction(
String arg1,
String arg2,
String arg3,
) {
return;
}
enum FirstEnum { firstItem }
const instance = FirstClass(
0,
0,
0,
);
Are you willing to submit a pull request to implement this rule?
Yes
For dart code is better to avoid use void arrow function, for several reasons:
return
is added to such function:void funcA() => a += 55;
function(){return $.a=$.a+55}
Please describe what the rule should do:
it will ask not to use void arrow function
What category of rule is this? (place an "X" next to just one item)
[ ] Warns about a potential error (problem)
[X] Suggests an alternate way of doing something (suggestion)
[ ] Other (please specify:)
Provide 2-3 code examples that this rule will warn about (it will be better if you can provide both good and bad examples):
//bad
void funcA() => a += 55;
//good
void funcA() {
a += 55;
}
Are you willing to submit a pull request to implement this rule?
yes
Issue a warning when there is a number literal in expression, except -1/+1/0. Recommend to extract magic number to named constant.
Bad:
final foo = bar + 4; // no-magic-number warning here
Fix:
const baz = 4; // 4 is extracted as constant
final foo = bar + baz; // No more warning
No warnings for exceptional literals:
final lastIndex = myList.length - 1;
final quotedContentStart = 'blah-blah "quoted" blah'.indexOf('"') + 1;
final isReservedId = (x) => x < 0;
Inspired by TSLint rule
Is it possible to integrate these metrics into flutter analyze
? I tried but couldn't seem to get it to work
Allows to enforce declaration order in classes. For example:
member-ordering: [angular-inputs, angular-outputs, public, constructor, private]
Inspired by TSLint rule
Please describe what the rule should do:
Check for equal arguments passed to functions or method invocations.
If your rule is inspired by other please provide link to it:
What category of rule is this? (place an "X" next to just one item)
[X] Warns about a potential error (problem)
[ ] Suggests an alternate way of doing something (suggestion)
[ ] Other (please specify:)
Provide 2-3 code examples that this rule will warn about (it will be better if you can provide both good and bad examples):
class User {
final String firstName;
final String lastName;
const User(this.firstName, this.lastName);
}
User createUser(String firstName, String lastName) {
return User(
firstName,
firstName, // <--
);
}
void getUserData(User user) {
String getFullName(String firstName, String lastName) {
return firstName + ' ' + lastName;
}
final fullName = getFullName(
user.firstName,
user.firstName, // <--
);
}
Are you willing to submit a pull request to implement this rule?
Yes
MetricsAnalysisRecorder has unsafe API that can lead to runtime exceptions if startRecordFile()
and endRecordFile()
calls are unpaired.
This can be improved using Dispose pattern.
Suggested API changes:
MetricsRecordsStore
with two methods:
records
with same signature as MetricsAnalysisRecorder.records
void recordFile(String filePath, String rootDirectory, void f(MetricsRecordsBuilder))
MetricsRecordsBuilder
that should expose methods recordComponent
, recordFunction
, recordIssues
with same signatures as corresponding methods in MetricsAnalysisRecorder.records
.MetricsAnalysisRecorder
create private copies of startRecordFile
, endRecordFile
, recordComponent
, recordFunction
, recordIssues
and make public versions call private versionsMetricsAnalysisRecorder
implement both of this interfaces
recordFile
should implement Dispose
pattern - call private _startRecordFile
, then pass this
to supplied lambda and execute _endRecordFile
at the end.
void recordFile(String filePath, String rootDirectory, void f(MetricsRecordsBuilder) {
_startRecordFile(filePath, rootDirectory);
f(this);
_endRecordFile()
}
startRecordFile
, endRecordFile
, recordComponent
, recordFunction
, recordIssues
as deprecated in favour of MetricsRecordsStore.recordFile
methodPlease describe what the rule should do:
avoid named from keywords list https://dart.dev/guides/language/language-tour#keywords
If your rule is inspired by other please provide link to it:
What category of rule is this? (place an "X" next to just one item)
[ X] Warns about a potential error (problem)
[ ] Suggests an alternate way of doing something (suggestion)
[ ] Other (please specify:)
Provide 2-3 code examples that this rule will warn about (it will be better if you can provide both good and bad examples):
void main() {
const abstract = 123;
const import = 123;
const as = 123;
const export = 123;
const interface = 123;
const sync = 123;
const async = 123;
const await = 123;
const extension = 123;
const library = 123;
const external = 123;
const mixin = 123;
const factory = 123;
const typedef = 123;
const on = 123;
const operator = 123;
const part = 123;
const covariant = 123;
const Function = 123;
const get = 123;
const yield = 123;
const deferred = 123;
const hide = 123;
const set = 123;
const show = 123;
const dynamic = 123;
const implements = 123;
const static = 123;
}
Are you willing to submit a pull request to implement this rule?
may be
Issue a warning when literal value is lhs in binary expressions.
Bad:
final a = 1 + b;
Good:
final a = b + 1;
Inspired by TSLint rule
What do you want to discuss?
I'm trying to know why the line of code reported by the tool isn't exactly the line of code of the file itself. I assume this is intended but I just need to know the reason behind and how the tool does it technically.
Line of code reported by the tool: 18
Line of code inside the file: 37
Please describe what the rule should do:
avoid export from another package
If your rule is inspired by other please provide link to it:
What category of rule is this? (place an "X" next to just one item)
[ X] Warns about a potential error (problem)
[ ] Suggests an alternate way of doing something (suggestion)
[ ] Other (please specify:)
Provide 2-3 code examples that this rule will warn about (it will be better if you can provide both good and bad examples):
For example current package has name current_package.
export 'package:another_package/src/math.dart'; //<--- Bad
export 'package:current_package/src/some_lib_1.dart';
export 'package:current_package/src/some_lib_2.dart';
Are you willing to submit a pull request to implement this rule?
may be
Issue a warning when there is a if-else block and same variable is written to in both branches.
Bad:
var myVar;
if (someTest) {
myVar = a;
} else {
myVar = b;
}
Good:
var myVar = someTest ? a : b;
Inspired by TSLint rule
Please describe what the rule should do:
Warns when return type is FutureOr<T>
, because end users need to check whether get back a T or a Future before they can do anything useful.
What category of rule is this? (place an "X" next to just one item)
[X] Warns about a potential error (problem)
[ ] Suggests an alternate way of doing something (suggestion)
[ ] Other (please specify:)
Provide 2-3 code examples that this rule will warn about (it will be better if you can provide both good and bad examples):
Bad:
FutureOr<int> triple(FutureOr<int> value) {
if (value is int) return value * 3;
return (value as Future<int>).then((v) => v * 3);
}
Good:
Future<int> triple(FutureOr<int> value) async => (await value) * 3;
Are you willing to submit a pull request to implement this rule?
Yes
Migrate current approach with strings in tests to separate dart files with examples. It will improve maintainability and readability of our tests.
Add rules for static field/method in member-ordering rule
What rule do you want to change?
member-ordering
How will the change be implemented? (New option, new default behavior, etc.)?
new option, just we will be able to make order for static methods/fields too
Please provide some example code that this change will affect:
class RescheduleUpdateComponent {
@HostBinding('class')
static const String hostClass = 'reschedule-update';
final DateTimeFormatter _dateTimeFormatter;
@HostBinding(‘class.active’)
bool get isActive() => _viewState.isActive;
}
What does the rule currently do for this code?
What will the rule do after it's changed?
can make particular order for static field/method
Are you willing to submit a pull request to implement this change?
I
Some field cases with false-positivish warnings:
final someDay = DateTime(2006, 12, 1); // DateTime has no const constructor, so there is always a warning or each int should be defined as const separately
Future.delayed(const Duration(seconds: 5)); // Triggered despite const constructor.
...
const delay = Duration(seconds: 5));
Future.delayed(delay); // This is fine. Not sure if should be fixed
... Intl.message(..., example: const <String, int>{ 'Assigneed': 3 } // Warning
So far it looks like rule should be altered to not trigger if magic number is inside const constructors and number literals in other const literals.
DateTime
should be made an exception, since it doesn't have a const constructor and putting every argument in separate const declaration is inconvenient.
Please describe what the rule should do:
Enforces ordering for @Component
Angular annotation arguments. Order should be configurable.
Available options:
What category of rule is this? (place an "X" next to just one item)
[ ] Warns about a potential error (problem)
[ ] Suggests an alternate way of doing something (suggestion)
[x] Other (please specify: enforces specific order)
Provide 2-3 code examples that this rule will warn about (it will be better if you can provide both good and bad examples):
With given config:
- selector
- providers
- change-detection
Bad:
@Component(
changeDetection: ChangeDetectionStrategy.OnPush,
selector: 'component-selector',
)
Good:
@Component(
selector: 'component-selector',
changeDetection: ChangeDetectionStrategy.OnPush,
)
Are you willing to submit a pull request to implement this rule?
Yes
We should provide correction to CodeIssue to enable rule quick fix.
Right now it's neccessary to create a bunch of internal classes and orchestrate them to create a report.
There should be a simpler way to perform common scenarios, preferably with a single function.
Example:
metrics --root-folder lib test
will produce empty report because files in test are not in lib
directory. This should produce at least a warning.
Please describe what the rule should do:
Check for potential null dereference in conditional expressions and blocks.
If your rule is inspired by other please provide link to it:
https://www.viva64.com/en/w/v6008/
What category of rule is this? (place an "X" next to just one item)
[X] Warns about a potential error (problem)
[ ] Suggests an alternate way of doing something (suggestion)
[ ] Other (please specify:)
Provide 2-3 code examples that this rule will warn about (it will be better if you can provide both good and bad examples):
if (obj != null || obj.foo()) { ... } // in obj.foo invocation obj could be null
if (obj == null && obj.foo()) { ... } // in obj.foo invocation obj is always null
if (obj == null) {
...
var bar = obj.foo(); // in obj.foo invocation obj is always null
...
}
Are you willing to submit a pull request to implement this rule?
Yes
Please describe what the rule should do:
Check for equal then and else statements.
If your rule is inspired by other please provide link to it:
https://www.viva64.com/en/w/v6004/
What category of rule is this? (place an "X" next to just one item)
[X] Warns about a potential error (problem)
[ ] Suggests an alternate way of doing something (suggestion)
[ ] Other (please specify:)
Provide 2-3 code examples that this rule will warn about (it will be better if you can provide both good and bad examples):
if (condition) {
result = value;
} else {
result = value;
}
result = condition ? value : value;
Are you willing to submit a pull request to implement this rule?
Yes
Issues a warning for class method that doesn't use class fields
Inspired by TSLint rule
When running with non-default --root-folder
argument validation erroneously fails, because existance of directory is checked relative to current folder instead of specified root-folder.
Example:
metrics --root-folder lib src
in this repo fails with Can't find directory src
.
It is an awesome tool
I didn't know it is there before so I wonder if you could promote it on the dart linter team or make pull requests to merge it to the main tool?
dart-lang/linter#2302
Please describe what the rule should do:
Checks for redundant async
.
Cases where async
is useful include:
await
.async
and then throw
is shorter than return Future.error(...)
.async
is shorter than Future.value(...)
.What category of rule is this? (place an "X" next to just one item)
[X] Warns about a potential error (problem)
[ ] Suggests an alternate way of doing something (suggestion)
[ ] Other (please specify:)
Provide 2-3 code examples that this rule will warn about (it will be better if you can provide both good and bad examples):
Bad:
Future<void> afterTwoThings(Future<void> first, Future<void> second) async {
return Future.wait([first, second]);
}
Good:
Future<void> usesAwait(Future<String> later) async {
print(await later);
}
Future<void> asyncError() async {
throw 'Error!';
}
Future<void> asyncValue() async => 'value';
Are you willing to submit a pull request to implement this rule?
Yes
Please describe what the rule should do:
Warns when return type is Future
or Future<Null>
instead of a Future<void>
.
What category of rule is this? (place an "X" next to just one item)
[X] Warns about a potential error (problem)
[ ] Suggests an alternate way of doing something (suggestion)
[ ] Other (please specify:)
Provide 2-3 code examples that this rule will warn about (it will be better if you can provide both good and bad examples):
Bad:
Future schedule(void Function callback) => _scheduler.add(callback);
Future<Null> (void Function callback) => _scheduler.add(callback);
Good:
Future<void> (void Function callback) => _scheduler.add(callback);
Are you willing to submit a pull request to implement this rule?
Yes
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.