Skip to content

Commit

Permalink
Rename custom lints to use snake_case
Browse files Browse the repository at this point in the history
  • Loading branch information
vova-beloded-solid committed Nov 9, 2023
1 parent 375b574 commit 4caad01
Show file tree
Hide file tree
Showing 55 changed files with 246 additions and 246 deletions.
4 changes: 2 additions & 2 deletions example/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ custom_lint:
- avoid_global_state
- avoid_returning_widgets
- avoid_unnecessary_setstate
- double-literal-format
- avoid-unnecessary-type-assertions
- double_literal_format
- avoid_unnecessary_type_assertions
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
part of 'avoid_unnecessary_type_assertions_rule.dart';

/// A Quick fix for `avoid-unnecessary-type-assertions` rule
/// A Quick fix for `avoid_unnecessary_type_assertions` rule
/// Suggests to remove unnecessary assertions
class _UnnecessaryTypeAssertionsFix extends DartFix {
@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ const operatorIsName = 'is';
/// The name of 'whereType' method
const whereTypeMethodName = 'whereType';

/// A `avoid-unnecessary-type-assertions` rule which
/// An `avoid_unnecessary_type_assertions` rule which
/// warns about unnecessary usage of `is` and `whereType` operators
class AvoidUnnecessaryTypeAssertions extends SolidLintRule {
/// The [LintCode] of this lint rule that represents
/// the error whether we use bad formatted double literals.
static const lintName = 'avoid-unnecessary-type-assertions';
static const lintName = 'avoid_unnecessary_type_assertions';

static const _unnecessaryIsCode = LintCode(
name: lintName,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
part of 'avoid_unnecessary_type_casts_rule.dart';

/// A Quick fix for `avoid-unnecessary-type-assertions` rule
/// A Quick fix for `avoid_unnecessary_type_casts` rule
/// Suggests to remove unnecessary assertions
class _UnnecessaryTypeCastsFix extends DartFix {
@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import 'package:solid_lints/models/solid_lint_rule.dart';

part 'avoid_unnecessary_type_casts_fix.dart';

/// A `avoid-unnecessary-type-casts` rule which
/// An `avoid_unnecessary_type_casts` rule which
/// warns about unnecessary usage of `as` operator
class AvoidUnnecessaryTypeCastsRule extends SolidLintRule {
/// The [LintCode] of this lint rule that represents
/// the error whether we use bad formatted double literals.
static const lintName = 'avoid-unnecessary-type-casts';
static const lintName = 'avoid_unnecessary_type_casts';

AvoidUnnecessaryTypeCastsRule._(super.config);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import 'package:solid_lints/lints/avoid_unrelated_type_assertions/avoid_unrelate
import 'package:solid_lints/models/rule_config.dart';
import 'package:solid_lints/models/solid_lint_rule.dart';

/// A `avoid-unrelated-type-assertions` rule which
/// A `avoid_unrelated_type_assertions` rule which
/// warns about unnecessary usage of `as` operator
class AvoidUnrelatedTypeAssertionsRule extends SolidLintRule {
/// The [LintCode] of this lint rule that represents
/// the error whether we use bad formatted double literals.
static const lintName = 'avoid-unrelated-type-assertions';
static const lintName = 'avoid_unrelated_type_assertions';

AvoidUnrelatedTypeAssertionsRule._(super.config);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import 'package:solid_lints/lints/avoid_unused_parameters/avoid_unused_parameter
import 'package:solid_lints/models/rule_config.dart';
import 'package:solid_lints/models/solid_lint_rule.dart';

/// A `avoid-unused-parameters` rule which
/// A `avoid_unused_parameters` rule which
/// warns about unused parameters
class AvoidUnusedParametersRule extends SolidLintRule {
/// The [LintCode] of this lint rule that represents
/// the error whether we use bad formatted double literals.
static const String lintName = 'avoid-unused-parameters';
static const String lintName = 'avoid_unused_parameters';

AvoidUnusedParametersRule._(super.config);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
part of 'double_literal_format_rule.dart';

/// A Quick fix for `double-literal-format` rule
/// A Quick fix for `double_literal_format` rule
/// Suggests the correct value for an issue
class _DoubleLiteralFormatFix extends DartFix {
@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'package:solid_lints/models/solid_lint_rule.dart';
part 'double_literal_format_fix.dart';
part 'double_literal_format_utils.dart';

/// A `double-literal-format` rule which
/// A `double_literal_format` rule which
/// checks that double literals should begin with 0. instead of just .,
/// and should not end with a trailing 0.
/// BAD:
Expand All @@ -18,7 +18,7 @@ part 'double_literal_format_utils.dart';
class DoubleLiteralFormatRule extends SolidLintRule {
/// The [LintCode] of this lint rule that represents
/// the error whether we use bad formatted double literals.
static const lintName = 'double-literal-format';
static const lintName = 'double_literal_format';

// Use different messages for different issues
/// The [LintCode] of this lint rule that represents
Expand Down
58 changes: 29 additions & 29 deletions lib/lints/member_ordering/config_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,37 +32,37 @@ import 'package:solid_lints/lints/member_ordering/models/member_group/method_mem
import 'package:solid_lints/lints/member_ordering/models/member_type.dart';
import 'package:solid_lints/lints/member_ordering/models/modifier.dart';

/// Helper class to parse member-ordering rule config
/// Helper class to parse member_ordering rule config
class MemberOrderingConfigParser {
static const _defaultOrderList = [
'public-fields',
'private-fields',
'public-getters',
'private-getters',
'public-setters',
'private-setters',
'public_fields',
'private_fields',
'public_getters',
'private_getters',
'public_setters',
'private_setters',
'constructors',
'public-methods',
'private-methods',
'public_methods',
'private_methods',
];

static const _defaultWidgetsOrderList = [
'constructor',
'named-constructor',
'const-fields',
'static-methods',
'final-fields',
'init-state-method',
'var-fields',
'init-state-method',
'private-methods',
'overridden-public-methods',
'build-method',
'named_constructor',
'const_fields',
'static_methods',
'final_fields',
'init_state_method',
'var_fields',
'init_state_method',
'private_methods',
'overridden_public_methods',
'build_method',
];

static final _regExp = RegExp(
'(overridden-|protected-)?(private-|public-)?(static-)?(late-)?'
'(var-|final-|const-)?(nullable-)?(named-)?(factory-)?',
'(overridden_|protected_)?(private_|public_)?(static_)?(late_)?'
'(var_|final_|const_)?(nullable_)?(named_)?(factory_)?',
);

/// Parse rule config for regular class order rules
Expand All @@ -84,15 +84,15 @@ class MemberOrderingConfigParser {
}

static MemberGroup? _parseGroup(String group) {
final lastGroup = group.endsWith('getters-setters')
? 'getters-setters'
: group.split('-').lastOrNull;
final lastGroup = group.endsWith('getters_setters')
? 'getters_setters'
: group.split('_').lastOrNull;
final type = MemberType.parse(lastGroup);
final result = _regExp.allMatches(group.toLowerCase());

final isNamedMethod = group.endsWith('-method');
final isNamedMethod = group.endsWith('_method');
if (isNamedMethod) {
final name = group.split('-method').first.replaceAll('-', '');
final name = group.split('_method').first.replaceAll('_', '');

return MethodMemberGroup.named(
name: name,
Expand All @@ -105,11 +105,11 @@ class MemberOrderingConfigParser {
if (hasGroups && type != null) {
final match = result.first;

final annotation = Annotation.parse(match.group(1)?.replaceAll('-', ''));
final modifier = Modifier.parse(match.group(2)?.replaceAll('-', ''));
final annotation = Annotation.parse(match.group(1)?.replaceAll('_', ''));
final modifier = Modifier.parse(match.group(2)?.replaceAll('_', ''));
final isStatic = match.group(3) != null;
final isLate = match.group(4) != null;
final keyword = FieldKeyword.parse(match.group(5)?.replaceAll('-', ''));
final keyword = FieldKeyword.parse(match.group(5)?.replaceAll('_', ''));
final isNullable = match.group(6) != null;
final isNamed = match.group(7) != null;
final isFactory = match.group(8) != null;
Expand Down
4 changes: 2 additions & 2 deletions lib/lints/member_ordering/member_ordering_rule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import 'package:solid_lints/lints/member_ordering/models/member_ordering_paramet
import 'package:solid_lints/models/rule_config.dart';
import 'package:solid_lints/models/solid_lint_rule.dart';

/// A `member-ordering` rule which
/// A `member_ordering` rule which
/// warns about class members being in wrong order
/// Custom order can be provided through config
class MemberOrderingRule extends SolidLintRule<MemberOrderingParameters> {
/// The [LintCode] of this lint rule that represents
/// the error whether we use bad formatted double literals.
static const lintName = 'member-ordering';
static const lintName = 'member_ordering';

static const _warningMessage = 'should be before';
static const _warningAlphabeticalMessage = 'should be alphabetically before';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import 'package:solid_lints/lints/member_ordering/models/member_group/member_gro
class MemberOrderingParameters {
/// Config keys
static const _orderConfig = 'order';
static const _widgetsOrderConfig = 'widgets-order';
static const _widgetsOrderConfig = 'widgets_order';
static const _alphabetizeConfig = 'alphabetize';
static const _alphabetizeByTypeConfig = 'alphabetize-by-type';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ import 'package:solid_lints/models/solid_lint_rule.dart';

// Inspired by ESLint (https://eslint.org/docs/rules/newline-before-return)

/// A `newline-before-return` rule which
/// A `newline_before_return` rule which
/// warns about missing newline before return
class NewlineBeforeReturnRule extends SolidLintRule {
/// The [LintCode] of this lint rule that represents the error if
/// newline is missing before return statement
static const String lintName = 'newline-before-return';
static const String lintName = 'newline_before_return';

NewlineBeforeReturnRule._(super.config);

Expand Down
4 changes: 2 additions & 2 deletions lib/lints/no_empty_block/no_empty_block_rule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import 'package:solid_lints/models/solid_lint_rule.dart';

// Inspired by TSLint (https://palantir.github.io/tslint/rules/no-empty/)

/// A `no-empty-block` rule which forbids having empty blocks.
/// A `no_empty_block` rule which forbids having empty blocks.
/// Excluding catch blocks and to-do comments
class NoEmptyBlockRule extends SolidLintRule {
/// The [LintCode] of this lint rule that represents
/// the error whether left empty block.
static const String lintName = 'no-empty-block';
static const String lintName = 'no_empty_block';

NoEmptyBlockRule._(super.config);

Expand Down
4 changes: 2 additions & 2 deletions lib/lints/no_equal_then_else/no_equal_then_else_rule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import 'package:solid_lints/models/solid_lint_rule.dart';

// Inspired by PVS-Studio (https://www.viva64.com/en/w/v6004/)

/// A `no-equal-then-else` rule which warns about
/// A `no_equal_then_else` rule which warns about
/// unnecessary if statements and conditional expressions
class NoEqualThenElseRule extends SolidLintRule {
/// The [LintCode] of this lint rule that represents the error if
/// 'if' statements or conditional expression is redundant
static const String lintName = 'no-equal-then-else';
static const String lintName = 'no_equal_then_else';

NoEqualThenElseRule._(super.config);

Expand Down
4 changes: 2 additions & 2 deletions lib/lints/no_magic_number/no_magic_number_rule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ import 'package:solid_lints/lints/no_magic_number/no_magic_number_visitor.dart';
import 'package:solid_lints/models/rule_config.dart';
import 'package:solid_lints/models/solid_lint_rule.dart';

/// A `no-magic-number` rule which forbids having numbers without variable
/// A `no_magic_number` rule which forbids having numbers without variable
class NoMagicNumberRule extends SolidLintRule<NoMagicNumberParameters> {
/// The [LintCode] of this lint rule that represents
/// the error when having magic number.
static const String lintName = 'no-magic-number';
static const String lintName = 'no_magic_number';

NoMagicNumberRule._(super.config);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// A data model class that represents the "prefer conditional expressions"
/// input parameters.
class PreferConditionalExpressionsParameters {
static const _ignoreNestedConfig = 'ignore-nested';
static const _ignoreNestedConfig = 'ignore_nested';

/// Should rule ignore nested if statements
final bool ignoreNested;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:analyzer/source/source_range.dart';
import 'package:custom_lint_builder/custom_lint_builder.dart';
import 'package:solid_lints/lints/prefer_conditional_expressions/prefer_conditional_expressions_visitor.dart';

/// A Quick fix for `avoid-unnecessary-type-assertions` rule
/// A Quick fix for `prefer_conditional_expressions` rule
/// Suggests to remove unnecessary assertions
class PreferConditionalExpressionsFix extends DartFix {
@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import 'package:solid_lints/models/solid_lint_rule.dart';

// Inspired by TSLint (https://palantir.github.io/tslint/rules/prefer-conditional-expression/)

/// A `prefer-conditional-expressions` rule which warns about
/// A `prefer_conditional_expressions` rule which warns about
/// simple if statements that can be replaced with conditional expressions
class PreferConditionalExpressionsRule
extends SolidLintRule<PreferConditionalExpressionsParameters> {
/// The [LintCode] of this lint rule that represents the error if number of
/// parameters reaches the maximum value.
static const lintName = 'prefer-conditional-expressions';
static const lintName = 'prefer_conditional_expressions';

PreferConditionalExpressionsRule._(super.config);

Expand Down
2 changes: 1 addition & 1 deletion lib/lints/prefer_first/prefer_first_fix.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:analyzer/error/error.dart';
import 'package:analyzer/source/source_range.dart';
import 'package:custom_lint_builder/custom_lint_builder.dart';

/// A Quick fix for `prefer-first` rule
/// A Quick fix for `prefer_first` rule
/// Suggests to replace iterable access expressions
class PreferFirstFix extends DartFix {
static const _replaceComment = "Replace with 'first'.";
Expand Down
4 changes: 2 additions & 2 deletions lib/lints/prefer_first/prefer_first_rule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import 'package:solid_lints/lints/prefer_first/prefer_first_visitor.dart';
import 'package:solid_lints/models/rule_config.dart';
import 'package:solid_lints/models/solid_lint_rule.dart';

/// A `prefer-first` rule which warns about
/// A `prefer_first` rule which warns about
/// usage of iterable[0] or iterable.elementAt(0)
class PreferFirstRule extends SolidLintRule {
/// The [LintCode] of this lint rule that represents the error if number of
/// parameters reaches the maximum value.
static const lintName = 'prefer-first';
static const lintName = 'prefer_first';

PreferFirstRule._(super.config);

Expand Down
2 changes: 1 addition & 1 deletion lib/lints/prefer_last/prefer_last_fix.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:analyzer/error/error.dart';
import 'package:analyzer/source/source_range.dart';
import 'package:custom_lint_builder/custom_lint_builder.dart';

/// A Quick fix for `prefer-last` rule
/// A Quick fix for `prefer_last` rule
/// Suggests to replace iterable access expressions
class PreferLastFix extends DartFix {
static const _replaceComment = "Replace with 'last'.";
Expand Down
4 changes: 2 additions & 2 deletions lib/lints/prefer_last/prefer_last_rule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import 'package:solid_lints/lints/prefer_last/prefer_last_visitor.dart';
import 'package:solid_lints/models/rule_config.dart';
import 'package:solid_lints/models/solid_lint_rule.dart';

/// A `prefer-last` rule which warns about
/// A `prefer_last` rule which warns about
/// usage of iterable[length-1] or iterable.elementAt(length-1)
class PreferLastRule extends SolidLintRule {
/// The [LintCode] of this lint rule that represents the error if iterable
/// access can be simplified.
static const lintName = 'prefer-last';
static const lintName = 'prefer_last';

PreferLastRule._(super.config);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import 'package:solid_lints/models/rule_config.dart';
import 'package:solid_lints/models/solid_lint_rule.dart';
import 'package:solid_lints/utils/node_utils.dart';

/// A `prefer-match-file-name` rule which warns about
/// A `prefer_match_file_name` rule which warns about
/// mismatch between file name and declared element inside
class PreferMatchFileNameRule extends SolidLintRule {
/// The [LintCode] of this lint rule that represents the error if iterable
/// access can be simplified.
static const String lintName = 'prefer-match-file-name';
static const String lintName = 'prefer_match_file_name';
static final _onlySymbolsRegex = RegExp('[^a-zA-Z0-9]');

PreferMatchFileNameRule._(super.config);
Expand Down
6 changes: 3 additions & 3 deletions lib/utils/typecast_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import 'package:collection/collection.dart';
// Useful types for testing expressions' types

// TODO: consider to move here common functions for rules
// avoid-unnecessary-type-assertions
// avoid-unnecessary-type-casts (after implementation)
// avoid-unrelated-type-assertions (after implementation)
// avoid_unnecessary_type_assertions
// avoid_unnecessary_type_casts (after implementation)
// avoid_unrelated_type_assertions (after implementation)

/// A class for representing arguments for types checking methods
class TypeCast {
Expand Down
Loading

0 comments on commit 4caad01

Please sign in to comment.