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: enable more lint rules #346

Merged
merged 4 commits into from
Jul 6, 2022
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
20 changes: 20 additions & 0 deletions all_lint_rules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ linter:
- avoid_equals_and_hash_code_on_mutable_classes
- avoid_escaping_inner_quotes
- avoid_field_initializers_in_const_classes
- avoid_final_parameters
- avoid_function_literals_in_foreach_calls
- avoid_implementing_value_types
- avoid_init_to_null
Expand Down Expand Up @@ -70,16 +71,20 @@ linter:
- cast_nullable_to_non_nullable
- close_sinks
- comment_references
- conditional_uri_does_not_exist
- constant_identifier_names
- control_flow_in_finally
- curly_braces_in_flow_control_structures
- depend_on_referenced_packages
- deprecated_consistency
- diagnostic_describe_all_properties
- directives_ordering
- discarded_futures
- do_not_use_environment
- empty_catches
- empty_constructor_bodies
- empty_statements
- eol_at_end_of_file
- exhaustive_cases
- file_names
- flutter_style_todos
Expand All @@ -99,9 +104,12 @@ linter:
- no_adjacent_strings_in_list
- no_default_cases
- no_duplicate_case_values
- no_leading_underscores_for_library_prefixes
- no_leading_underscores_for_local_identifiers
- no_logic_in_create_state
- no_runtimeType_toString
- non_constant_identifier_names
- noop_primitive_operations
- null_check_on_nullable_type_parameter
- null_closures
- omit_local_variable_types
Expand Down Expand Up @@ -129,6 +137,7 @@ linter:
- prefer_final_fields
- prefer_final_in_for_each
- prefer_final_locals
- prefer_final_parameters
- prefer_for_elements_to_map_fromIterable
- prefer_foreach
- prefer_function_declarations_over_variables
Expand All @@ -155,7 +164,9 @@ linter:
- public_member_api_docs
- recursive_getters
- require_trailing_commas
- secure_pubspec_urls
- sized_box_for_whitespace
- sized_box_shrink_expand
- slash_for_doc_comments
- sort_child_properties_last
- sort_constructors_first
Expand All @@ -170,11 +181,14 @@ linter:
- unnecessary_await_in_return
- unnecessary_brace_in_string_interps
- unnecessary_const
- unnecessary_constructor_name
- unnecessary_final
- unnecessary_getters_setters
- unnecessary_lambdas
- unnecessary_late
- unnecessary_new
- unnecessary_null_aware_assignments
- unnecessary_null_aware_operator_on_extension_on_nullable
- unnecessary_null_checks
- unnecessary_null_in_if_null_operators
- unnecessary_nullable_for_final_variable_declarations
Expand All @@ -185,9 +199,13 @@ linter:
- unnecessary_string_escapes
- unnecessary_string_interpolations
- unnecessary_this
- unnecessary_to_list_in_spreads
- unrelated_type_equality_checks
- unsafe_html
- use_build_context_synchronously
- use_colored_box
- use_decorated_box
- use_enums
- use_full_hex_values_for_flutter_colors
- use_function_type_syntax_for_parameters
- use_if_null_to_convert_nulls_to_bools
Expand All @@ -199,6 +217,8 @@ linter:
- use_rethrow_when_possible
- use_setters_to_change_properties
- use_string_buffers
- use_super_parameters
- use_test_throws_matchers
- use_to_and_as_if_applicable
- valid_regexps
- void_checks
36 changes: 11 additions & 25 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@

include: all_lint_rules.yaml
analyzer:
strong-mode:
implicit-casts: false
implicit-dynamic: false
language:
strict-casts: true
strict-inference: true
strict-raw-types: true
errors:
# Otherwise cause the import of all_lint_rules to warn because of some rules conflicts.
# We explicitly enabled even conflicting rules and are fixing the conflict
# in this file
# in this file.
included_file_warning: ignore

linter:
Expand All @@ -31,16 +32,8 @@ linter:
public_member_api_docs: false

always_put_control_body_on_new_line: false
comment_references: true
prefer_constructors_over_static_methods: true
prefer_final_fields: true
omit_local_variable_types: true
avoid_equals_and_hash_code_on_mutable_classes: false

#############
# Conflicts with 'unecessary_final'
prefer_final_locals: true

# Deos not always make code more readable.
cascade_invocations: false

# Conflicts with `prefer_single_quotes`
Expand All @@ -54,7 +47,7 @@ linter:
always_specify_types: false

# Incompatible with `prefer_final_locals`
# Having immutable local variables makes larger functions more predictible
# Having immutable local variables makes larger functions more predictable
# so we will use `prefer_final_locals` instead.
unnecessary_final: false

Expand All @@ -77,20 +70,12 @@ linter:
# especially as a library.
avoid_catches_without_on_clauses: false

# Boring as it sometimes force a line of 81 characters to be split in two.
# As long as we try to respect that 80 characters limit, going slightly
# above is fine.
lines_longer_than_80_chars: false

# Conflicts with disabling `implicit-dynamic`
avoid_annotating_with_dynamic: false

# conflicts with `prefer_relative_imports`
always_use_package_imports: false

# Disabled for now until NNBD as it otherwise conflicts with `missing_return`
no_default_cases: false

# False positive, null checks don't need a message
prefer_asserts_with_message: false

Expand All @@ -100,8 +85,9 @@ linter:
# Too many false positive (builders)
diagnostic_describe_all_properties: false

# false positives (setter-like functions)
avoid_positional_boolean_parameters: false

# Does not apply to providers
prefer_const_constructors_in_immutables: false

# Not a common style and would add a lot of verbosity to function signature.
# 'parameter_assignments' already enforces this to an extent.
prefer_final_parameters: false
31 changes: 20 additions & 11 deletions packages/conventional_commit/lib/conventional_commit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ enum SemverReleaseType {
}

/// A representation of a parsed conventional commit message.
///
/// Parsing is based upon the Conventional Commits 1.0.0 specification available
/// at https://www.conventionalcommits.org/en/v1.0.0/
class ConventionalCommit {
Expand All @@ -57,7 +58,7 @@ class ConventionalCommit {

/// Create a new [ConventionalCommit] from a commit message [String].
///
/// ```dart
/// ```dart main
/// var message = '''
/// type(scope)!: commit message description
///
Expand Down Expand Up @@ -185,13 +186,16 @@ class ConventionalCommit {
/// The type specified in this commit, e.g. `feat`.
final String? type;

/// Whether this commit was a breaking change, e.g. `!` was specified after the scopes in the commit message.
/// Whether this commit was a breaking change, e.g. `!` was specified after
/// the scopes in the commit message.
final bool isBreakingChange;

/// The description of the breaking change, e.g. the text after BREAKING CHANGE: <description>.
/// The description of the breaking change, e.g. the text after BREAKING
/// CHANGE: <description>.
///
/// Will be null if [isBreakingChange] is false. Defaults to [description] if
/// the `BREAKING CHANGE:` footer format was not used, e.g. only `!` after the
/// commit type was specified..
/// commit type was specified.
final String? breakingChangeDescription;

/// Whether this commit was a merge commit, e.g. `Merge #24 into main`
Expand All @@ -200,23 +204,27 @@ class ConventionalCommit {
/// Commit message description (text after the scopes).
final String? description;

/// The original commit message header (this is normally the first line of the commit message.)
/// The original commit message header (this is normally the first line of the
/// commit message.)
final String header;

/// An optional body describing the change in more detail.
///
/// Note this can contain multiple paragraphs separated by new lines.
final String? body;

/// Footers other than BREAKING CHANGE: <description> may be provided and
/// follow a convention similar to git trailer format.
/// A footer’s token MUST use "-" in place of whitespace characters,
/// e.g., Acked-by (this helps differentiate the footer section from a
/// multi-paragraph body). An exception is made for BREAKING CHANGE, which
/// MAY also be used as a token.
///
/// A footer’s token MUST use "-" in place of whitespace characters, e.g.,
/// Acked-by (this helps differentiate the footer section from a
/// multi-paragraph body). An exception is made for BREAKING CHANGE, which MAY
/// also be used as a token.
final List<String> footers;

// TODO(Salakar): this api should probably not be in this package
/// Whether this commit should trigger a version bump in it's residing package.
/// Whether this commit should trigger a version bump in it's residing
/// package.
bool get isVersionableCommit {
if (isMergeCommit) return false;
return isBreakingChange ||
Expand All @@ -232,7 +240,8 @@ class ConventionalCommit {
}

// TODO(Salakar): this api should probably not be in this package
/// Returns the [SemverReleaseType] for this commit, e.g. [SemverReleaseType.major].
/// Returns the [SemverReleaseType] for this commit, e.g.
/// [SemverReleaseType.major].
SemverReleaseType get semverReleaseType {
if (isBreakingChange) {
return SemverReleaseType.major;
Expand Down
4 changes: 2 additions & 2 deletions packages/melos/bin/melos.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ Future<void> main(List<String> arguments) async {
if (!isUpToDate) {
final latestVersion = await pubUpdater.getLatestVersion(packageName);
final shouldUpdate = utils.promptBool(
message:
'There is a new version of $packageName available ($latestVersion). Would you like to update?',
message: 'There is a new version of $packageName available '
'($latestVersion). Would you like to update?',
defaultsTo: true,
);
if (shouldUpdate) {
Expand Down
5 changes: 3 additions & 2 deletions packages/melos/lib/src/command_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import 'workspace_configs.dart';
///
/// To run a command, do:
///
/// ```dart
/// ```dart main
/// final melos = MelosCommandRunner();
///
/// await melos.run(['bootstrap']);
Expand All @@ -42,7 +42,8 @@ class MelosCommandRunner extends CommandRunner<void> {
MelosCommandRunner(MelosWorkspaceConfig config)
: super(
'melos',
'A CLI tool for managing Dart & Flutter projects with multiple packages.',
'A CLI tool for managing Dart & Flutter projects with multiple '
'packages.',
usageLineLength: terminalWidth,
) {
argParser.addFlag(
Expand Down
4 changes: 2 additions & 2 deletions packages/melos/lib/src/command_runner/base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ abstract class MelosCommand extends Command<void> {
late final logger =
MelosLogger(global.verbose ? Logger.verbose() : Logger.standard());

/// The `melos.yaml` configuration for this command.
/// see [ArgParser.allowTrailingOptions]
/// The `melos.yaml` configuration for this command. see
/// [ArgParser.allowTrailingOptions]
bool get allowTrailingOptions => true;

/// Overridden to support line wrapping when printing usage.
Expand Down
5 changes: 2 additions & 3 deletions packages/melos/lib/src/command_runner/bootstrap.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import 'dart:async';

import '../commands/runner.dart';
import '../workspace_configs.dart';

import 'base.dart';

class BootstrapCommand extends MelosCommand {
Expand All @@ -35,8 +34,8 @@ class BootstrapCommand extends MelosCommand {

@override
final String description =
'Initialize the workspace, link local packages together and install remaining package dependencies. '
'Supports all package filtering options.';
'Initialize the workspace, link local packages together and install '
'remaining package dependencies. Supports all package filtering options.';

@override
FutureOr<void>? run() {
Expand Down
5 changes: 2 additions & 3 deletions packages/melos/lib/src/command_runner/clean.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import '../commands/runner.dart';
import '../workspace_configs.dart';

import 'base.dart';

class CleanCommand extends MelosCommand {
Expand All @@ -30,8 +29,8 @@ class CleanCommand extends MelosCommand {

@override
final String description = 'Clean this workspace and all packages. '
'This deletes the temporary pub & ide files such as ".packages" & ".flutter-plugins". '
'Supports all package filtering options.';
'This deletes the temporary pub & ide files such as ".packages" & '
'".flutter-plugins". Supports all package filtering options.';

@override
Future<void> run() async {
Expand Down
6 changes: 4 additions & 2 deletions packages/melos/lib/src/command_runner/exec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class ExecCommand extends MelosCommand {
'fail-fast',
abbr: 'f',
help:
'Whether exec should fail fast and not execute the script in further packages if the script fails in a individual package.',
'Whether exec should fail fast and not execute the script in further '
'packages if the script fails in a individual package.',
);
}

Expand All @@ -41,7 +42,8 @@ class ExecCommand extends MelosCommand {

@override
final String description =
'Execute an arbitrary command in each package. Supports all package filtering options.';
'Execute an arbitrary command in each package. Supports all package '
'filtering options.';

@override
Future<void> run() async {
Expand Down
6 changes: 4 additions & 2 deletions packages/melos/lib/src/command_runner/list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ class ListCommand extends MelosCommand {
abbr: 'r',
negatable: false,
help:
'When printing output, use package paths relative to the root of the workspace.',
'When printing output, use package paths relative to the root of the '
'workspace.',
);
argParser.addFlag(
'json',
Expand All @@ -66,7 +67,8 @@ class ListCommand extends MelosCommand {

@override
final String description =
'List local packages in various output formats. Supports all package filtering options.';
'List local packages in various output formats. Supports all package '
'filtering options.';

@override
final String invocation = 'melos list';
Expand Down
4 changes: 2 additions & 2 deletions packages/melos/lib/src/command_runner/publish.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ class PublishCommand extends MelosCommand {

@override
final String description =
'Publish any unpublished packages or package versions in your repository to pub.dev. '
'Dry run is on by default.';
'Publish any unpublished packages or package versions in your repository '
'to pub.dev. Dry run is on by default.';

@override
Future<void> run() async {
Expand Down
Loading