Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(analysis): 🕵️ add more lint rules and explain ignored diagnostics #523

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,22 @@ include: package:very_good_analysis/analysis_options.yaml
linter:
rules:
- annotate_redeclares
- avoid_annotating_with_dynamic
- avoid_classes_with_only_static_members
- avoid_implementing_value_types
- avoid_types_on_closure_parameters
- do_not_use_environment
- document_ignores
- matching_super_parameters
- no_literal_bool_comparisons
- prefer_expression_function_bodies
- prefer_foreach
- prefer_mixin
- type_literal_in_constant_pattern
- unintended_html_in_doc_comment
- unnecessary_library_name
- unnecessary_null_aware_operator_on_extension_on_nullable
- unreachable_from_main

analyzer:
errors:
Expand Down
1 change: 1 addition & 0 deletions example/main.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// For documentation purposes.
// ignore_for_file: unnecessary_statements, cascade_invocations

import 'package:music_notes/music_notes.dart';
Expand Down
1 change: 1 addition & 0 deletions lib/src/interval/interval.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// To allow major (M) and minor (m) static constant names.
// ignore_for_file: constant_identifier_names

import 'package:meta/meta.dart' show immutable;
Expand Down
1 change: 1 addition & 0 deletions lib/src/interval/interval_class.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// To allow major (M) and minor (m) static constant names.
// ignore_for_file: constant_identifier_names

import 'dart:collection' show SplayTreeSet;
Expand Down
1 change: 1 addition & 0 deletions lib/src/interval/quality.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ sealed class Quality implements Comparable<Quality> {
@override
int compareTo(Quality other) => compareMultiple([
() => semitones.compareTo(other.semitones),
// TODO(albertms10): rewrite without relying on `runtimeType`.
// ignore: no_runtimetype_tostring
() => '$runtimeType'.compareTo('${other.runtimeType}'),
]);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/note/pitch_class.dart
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ final class PitchClass extends Scalable<PitchClass>
Note resolveClosestSpelling([Accidental? preferredAccidental]) {
try {
return resolveSpelling(preferredAccidental);
// ignore: avoid_catching_errors
// ignore: avoid_catching_errors to catch `ArgumentError`.
} on ArgumentError {
return resolveSpelling();
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/scalable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'music.dart';
import 'note/pitch_class.dart';
import 'transposable.dart';

/// A interface for items that can form scales.
/// An interface for items that can form scales.
abstract class Scalable<T extends Scalable<T>>
with Enharmonic<PitchClass>
implements Transposable<T> {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/transposable.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'interval/interval.dart';

/// A interface for items that can be transposed.
/// An interface for items that can be transposed.
// ignore: one_member_abstracts
abstract interface class Transposable<T> {
/// Transposes this [T] by [interval].
Expand Down
12 changes: 6 additions & 6 deletions test/src/harmony/harmonic_function_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,25 +58,25 @@ void main() {
group('.hashCode', () {
test('returns the same hashCode for equal HarmonicFunctions', () {
expect(
// ignore: prefer_const_constructors, prefer_const_literals_to_create_immutables
// ignore: prefer_const_constructors, prefer_const_literals_to_create_immutables test
HarmonicFunction([ScaleDegree.i]).hashCode,
// ignore: prefer_const_constructors, prefer_const_literals_to_create_immutables
// ignore: prefer_const_constructors, prefer_const_literals_to_create_immutables test
HarmonicFunction([ScaleDegree.i]).hashCode,
);
expect(
// ignore: prefer_const_constructors, prefer_const_literals_to_create_immutables
// ignore: prefer_const_constructors, prefer_const_literals_to_create_immutables test
HarmonicFunction([
// ignore: prefer_const_constructors
// ignore: prefer_const_constructors test
ScaleDegree(
2,
quality: ImperfectQuality.major,
inversion: 1,
semitonesDelta: -1,
),
]).hashCode,
// ignore: prefer_const_constructors, prefer_const_literals_to_create_immutables
// ignore: prefer_const_constructors, prefer_const_literals_to_create_immutables test
HarmonicFunction([
// ignore: prefer_const_constructors
// ignore: prefer_const_constructors test
ScaleDegree(
2,
quality: ImperfectQuality.major,
Expand Down
4 changes: 2 additions & 2 deletions test/src/interval/interval_class_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ void main() {
group('IntervalClass', () {
group('constructor', () {
test('creates a new IntervalClass from semitones', () {
// ignore: use_named_constants
// ignore: use_named_constants test
expect(const IntervalClass(8), IntervalClass.M3);
// ignore: use_named_constants
// ignore: use_named_constants test
expect(const IntervalClass(-2), IntervalClass.M2);
});
});
Expand Down
2 changes: 0 additions & 2 deletions test/src/note/accidental_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// ignore_for_file: use_named_constants

import 'dart:collection' show SplayTreeSet;

import 'package:music_notes/music_notes.dart';
Expand Down
20 changes: 10 additions & 10 deletions test/src/note/hearing_range_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,31 @@ void main() {
group('.hashCode', () {
test('returns the same hashCode for equal ClosestPitches', () {
expect(
// ignore: prefer_const_constructors
// ignore: prefer_const_constructors test
HearingRange(min: Frequency(1), max: Frequency(1000)).hashCode,
// ignore: prefer_const_constructors
// ignore: prefer_const_constructors test
HearingRange(min: Frequency(1), max: Frequency(1000)).hashCode,
);
expect(
// ignore: prefer_const_constructors
// ignore: prefer_const_constructors test
HearingRange(min: Frequency(10.646), max: Frequency(2345.3)).hashCode,
// ignore: prefer_const_constructors
// ignore: prefer_const_constructors test
HearingRange(min: Frequency(10.646), max: Frequency(2345.3)).hashCode,
);
});

test('returns different hashCodes for different ClosestPitches', () {
expect(
// ignore: prefer_const_constructors
// ignore: prefer_const_constructors test
HearingRange(min: Frequency(0), max: Frequency(30000)).hashCode,
// ignore: prefer_const_constructors
// ignore: prefer_const_constructors test
isNot(HearingRange(min: Frequency(2), max: Frequency(3)).hashCode),
);
expect(
// ignore: prefer_const_constructors
// ignore: prefer_const_constructors test
HearingRange(min: Frequency(10.6), max: Frequency(2345.3)).hashCode,
isNot(
// ignore: prefer_const_constructors
// ignore: prefer_const_constructors test
HearingRange(min: Frequency(10.7), max: Frequency(2345.6)).hashCode,
),
);
Expand All @@ -50,9 +50,9 @@ void main() {
test('ignores equal ClosestPitch instances in a Set', () {
final collection = {
HearingRange.human,
// ignore: prefer_const_constructors
// ignore: prefer_const_constructors test
HearingRange(min: Frequency(0), max: Frequency(1000)),
// ignore: prefer_const_constructors
// ignore: prefer_const_constructors test
HearingRange(min: Frequency(10), max: Frequency(20000)),
};
collection.addAll(collection);
Expand Down
4 changes: 2 additions & 2 deletions test/src/note/pitch_class_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ void main() {
group('PitchClass', () {
group('constructor', () {
test('creates a new PitchClass from semitones', () {
// ignore: use_named_constants
// ignore: use_named_constants test
expect(const PitchClass(-2), PitchClass.aSharp);
// ignore: use_named_constants
// ignore: use_named_constants test
expect(const PitchClass(13), PitchClass.cSharp);
});
});
Expand Down
4 changes: 2 additions & 2 deletions test/src/note/pitch_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1434,9 +1434,9 @@ void main() {
test('returns the same hashCode for equal Pitches', () {
expect(Note.c.inOctave(4).hashCode, Note.c.inOctave(4).hashCode);
expect(
// ignore: prefer_const_constructors
// ignore: prefer_const_constructors test
Pitch(Note.a, octave: 3).hashCode,
// ignore: prefer_const_constructors
// ignore: prefer_const_constructors test
Pitch(Note.a, octave: 3).hashCode,
);
});
Expand Down
6 changes: 3 additions & 3 deletions test/src/scale/scale_degree_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -143,17 +143,17 @@ void main() {

group('.hashCode', () {
test('returns the same hashCode for equal ScaleDegrees', () {
// ignore: prefer_const_constructors
// ignore: prefer_const_constructors test
expect(ScaleDegree(1).hashCode, ScaleDegree(1).hashCode);
expect(
// ignore: prefer_const_constructors
// ignore: prefer_const_constructors test
ScaleDegree(
2,
quality: ImperfectQuality.major,
inversion: 1,
semitonesDelta: -1,
).hashCode,
// ignore: prefer_const_constructors
// ignore: prefer_const_constructors test
ScaleDegree(
2,
quality: ImperfectQuality.major,
Expand Down
4 changes: 2 additions & 2 deletions test/src/scale/scale_pattern_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -659,9 +659,9 @@ void main() {
const ScalePattern([Interval.d5]),
ScalePattern.major,
ScalePattern.aeolian,
// ignore: equal_elements_in_set
// ignore: equal_elements_in_set test
ScalePattern.naturalMinor,
// ignore: equal_elements_in_set
// ignore: equal_elements_in_set test
ScalePattern.ionian,
ScalePattern.mixolydian,
ScalePattern.wholeTone,
Expand Down
6 changes: 3 additions & 3 deletions test/src/tuning/equal_temperament_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void main() {

group('operator ==()', () {
test('compares this EqualTemperament to other', () {
// ignore: prefer_const_constructors
// ignore: prefer_const_constructors test
expect(EqualTemperament.edo12(), EqualTemperament.edo12());
expect(
const EqualTemperament.edo12(),
Expand Down Expand Up @@ -93,9 +93,9 @@ void main() {
group('.hashCode', () {
test('returns the same hashCode for equal EqualTemperaments', () {
expect(
// ignore: prefer_const_constructors, prefer_const_literals_to_create_immutables
// ignore: prefer_const_constructors, prefer_const_literals_to_create_immutables test
EqualTemperament([1, 2]).hashCode,
// ignore: prefer_const_constructors, prefer_const_literals_to_create_immutables
// ignore: prefer_const_constructors, prefer_const_literals_to_create_immutables test
EqualTemperament([1, 2]).hashCode,
);
});
Expand Down