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

Chore/dcm linting #609

Closed
wants to merge 8 commits into from
Closed
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
72 changes: 45 additions & 27 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,10 @@ concurrency:

jobs:
test:
name: Test on ${{ matrix.os }}
name: Test
timeout-minutes: 30
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]

steps:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

Expand All @@ -37,35 +33,57 @@ jobs:
with:
sdk-version: ${{ github.event.inputs.sdk-version }}

# - name: Install DCM
# uses: CQLabs/setup-dcm@v1
# with:
# github_token: ${{ secrets.GITHUB_TOKEN }}

# - name: Run DCM
# uses: CQLabs/dcm-action@v1
# with:
# github_token: ${{ secrets.GITHUB_TOKEN }}
# folders: lib
- uses: invertase/github-action-dart-analyzer@v1
with:
fatal-infos: false


- name: Tests
uses: ./.github/actions/test
if: matrix.os != 'ubuntu-latest'

- name: Install DCM
uses: CQLabs/setup-dcm@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}

- name: Run DCM
uses: CQLabs/dcm-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
ci_key: oss
email: oss
folders: .
fatal_style: true
fatal_performance: true
fatal_warnings: true

- name: Install lcov
run: sudo apt-get install lcov
if: matrix.os == 'ubuntu-latest'
run: sudo apt-get install lcov

- name: Run tests
uses: ./.github/actions/test
if: matrix.os == 'ubuntu-latest'
with:
with-coverage: 'true'

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
if: matrix.os == 'ubuntu-latest'
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}


test-os:
name: Test on ${{ matrix.os }}
needs: test
timeout-minutes: 30
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-latest, windows-latest]

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Prepare environment
uses: ./.github/actions/prepare
with:
sdk-version: ${{ github.event.inputs.sdk-version }}

- name: Tests
uses: ./.github/actions/test
8 changes: 5 additions & 3 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,17 @@ dart_code_metrics:
only-in-src: true
prefer-match-file-name: false
prefer-correct-callback-field-name: false
# Remove later when cleaning up
prefer-single-widget-per-file: false
# End of remove later
match-getter-setter-field-names: false
avoid-duplicate-cascades: false
prefer-dedicated-media-query-methods: false
avoid-shadowing: false
avoid-duplicate-initializers: false
enum-constants-ordering: false
avoid-accessing-collections-by-constant-index: false
avoid-unsafe-collection-methods: false
move-variable-closer-to-its-usage: false
prefer-prefixed-global-constants: false
avoid-nullable-interpolation: false
avoid-returning-widgets: false
arguments-ordering:
child-last: true
Expand Down
2 changes: 2 additions & 0 deletions bin/compile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Future<void> main() async {

if (os != 'macos' && os != 'linux') {
print('Unsupported OS. Only MacOS and Linux are supported.');

return;
}

Expand All @@ -28,6 +29,7 @@ Future<void> main() async {
// Error checking for compile process
if (compileResult.exitCode != 0) {
print('Error occurred in compilation:\n ${compileResult.stderr}');

return;
}

Expand Down
2 changes: 2 additions & 0 deletions lib/src/commands/base_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ abstract class BaseCommand extends Command<int> {
if (arg == 'null' || (arg == null || arg.isEmpty)) {
return null;
}

return arg;
}

/// Gets the parsed command-line option named [name] as `List<String>`.
// ignore: prefer-correct-json-casts
List<String?> stringsArg(String name) => argResults![name] as List<String>;
@override
String get invocation => 'fvm $name';
Expand Down
10 changes: 5 additions & 5 deletions lib/src/commands/config_command.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import 'package:fvm/constants.dart';
import 'package:fvm/fvm.dart';
import 'package:fvm/src/services/config_repository.dart';
import 'package:fvm/src/services/logger_service.dart';
import 'package:io/ansi.dart';
import 'package:io/io.dart';

import '../models/config_model.dart';
import '../services/config_repository.dart';
import '../services/logger_service.dart';
import '../utils/constants.dart';
import '../utils/context.dart';
import 'base_command.dart';

Expand All @@ -22,8 +22,8 @@ class ConfigCommand extends BaseCommand {
argParser.addFlag(
'update-check',
help: 'Checks if there is a new version of $kPackageName available.',
negatable: true,
defaultsTo: true,
negatable: true,
);
}
@override
Expand Down
8 changes: 5 additions & 3 deletions lib/src/commands/dart_command.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import 'package:args/args.dart';
import 'package:fvm/constants.dart';
import 'package:fvm/fvm.dart';
import 'package:fvm/src/utils/commands.dart';

import '../models/cache_flutter_version_model.dart';
import '../services/logger_service.dart';
import '../services/project_service.dart';
import '../utils/commands.dart';
import '../utils/constants.dart';
import '../workflows/ensure_cache.workflow.dart';
import 'base_command.dart';

Expand Down Expand Up @@ -40,6 +41,7 @@ class DartCommand extends BaseCommand {
// Running null will default to dart version on path
}
final results = await runDart(args, version: cacheVersion);

return results.exitCode;
}
}
41 changes: 21 additions & 20 deletions lib/src/commands/doctor_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ import 'dart:convert';
import 'dart:io';

import 'package:dart_console/dart_console.dart';
import 'package:fvm/constants.dart';
import 'package:fvm/exceptions.dart';
import 'package:fvm/fvm.dart';
import 'package:fvm/src/utils/console_utils.dart';
import 'package:fvm/src/utils/context.dart';
import 'package:fvm/src/utils/which.dart';
import 'package:io/io.dart';
import 'package:path/path.dart';

import '../models/config_model.dart';
import '../models/project_model.dart';
import '../services/logger_service.dart';
import '../services/project_service.dart';
import '../utils/console_utils.dart';
import '../utils/constants.dart';
import '../utils/context.dart';
import '../utils/exceptions.dart';
import '../utils/which.dart';
import 'base_command.dart';

/// Information about fvm environment
Expand All @@ -38,9 +40,9 @@ class DoctorCommand extends BaseCommand {
['Is Flutter Project', project.isFlutter ? 'Yes' : 'No'],
[
'Dart Tool Generator Version',
project.dartToolGeneratorVersion ?? 'Not available',
project.dartToolGeneratorVersion ?? 'N/A',
],
['Dart tool version', project.dartToolVersion ?? 'Not available'],
['Dart tool version', project.dartToolVersion ?? 'N/A'],
['.gitignore Present', project.gitignoreFile.existsSync() ? 'Yes' : 'No'],
['Config Present', project.hasConfig ? 'Yes' : 'No'],
['Pinned Version', project.pinnedVersion ?? 'None'],
Expand Down Expand Up @@ -68,10 +70,10 @@ class DoctorCommand extends BaseCommand {
table.insertRow([kVsCode]);
// Check for .vscode directory
final vscodeDir = Directory(join(project.path, '.vscode'));
final settingsPath = join(vscodeDir.path, 'settings.json');
final settingsFile = File(settingsPath);

if (vscodeDir.existsSync()) {
final settingsPath = join(vscodeDir.path, 'settings.json');
final settingsFile = File(settingsPath);
if (settingsFile.existsSync()) {
try {
final settings = jsonDecode(settingsFile.readAsStringSync());
Expand All @@ -87,14 +89,17 @@ class DoctorCommand extends BaseCommand {
table.insertRow(
['Matches pinned version:', sdkPath == relativeSymlinkPath],
);
} on FormatException {
} on FormatException catch (_, stackTrace) {
logger
..err('Error parsing Vscode settings.json on ${settingsFile.path}')
..err(
'Please use a tool like https://jsonformatter.curiousconcept.com to validate and fix it',
'Please use a tool like https://jsonlint.com to validate and fix it',
);
throw AppException(
'Could not get vscode settings, please check settings.json',
Error.throwWithStackTrace(
AppException(
'Could not get vscode settings, please check settings.json',
),
stackTrace,
);
}
} else {
Expand Down Expand Up @@ -134,9 +139,9 @@ class DoctorCommand extends BaseCommand {
final dartSdk = dartSdkFile.readAsStringSync();
final containsUserHome = dartSdk.contains(r'$USER_HOME$');
final containsProjectDir = dartSdk.contains(r'$PROJECT_DIR$');
final containsSymLinkName = dartSdk.contains('.fvm/flutter_sdk');

if (!containsUserHome && containsProjectDir) {
final containsSymLinkName = dartSdk.contains('.fvm/flutter_sdk');
if (containsSymLinkName) {
table.insertRow([
'SDK Path',
Expand All @@ -155,10 +160,7 @@ class DoctorCommand extends BaseCommand {
]);
}
} else {
table.insertRow([
kIntelliJ,
'No .idea folder found',
]);
table.insertRow([kIntelliJ, 'No .idea folder found']);
}

logger.write(table.toString());
Expand Down Expand Up @@ -198,7 +200,6 @@ class DoctorCommand extends BaseCommand {
logger.write(table.toString());
}

void printFVMDetails() {}
@override
Future<int> run() async {
final project = ProjectService.fromContext.findAncestor();
Expand Down
7 changes: 4 additions & 3 deletions lib/src/commands/exec_command.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import 'package:args/args.dart';
import 'package:args/command_runner.dart';
import 'package:fvm/constants.dart';
import 'package:fvm/fvm.dart';

import '../models/cache_flutter_version_model.dart';
import '../services/logger_service.dart';
import '../services/project_service.dart';
import '../utils/commands.dart';
import '../utils/constants.dart';
import '../workflows/ensure_cache.workflow.dart';
import 'base_command.dart';

Expand All @@ -31,7 +32,7 @@ class ExecCommand extends BaseCommand {
final cmd = argResults!.rest[0];

// Removes version from first arg
final execArgs = [...argResults!.rest]..removeAt(0);
final execArgs = [...?argResults?.rest]..removeAt(0);

// If no version is provided try to use global
CacheFlutterVersion? cacheVersion;
Expand Down
12 changes: 7 additions & 5 deletions lib/src/commands/flutter_command.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import 'package:args/args.dart';
import 'package:fvm/constants.dart';
import 'package:fvm/exceptions.dart';
import 'package:fvm/fvm.dart';
import 'package:fvm/src/services/logger_service.dart';

import '../models/cache_flutter_version_model.dart';
import '../services/logger_service.dart';
import '../services/project_service.dart';
import '../utils/commands.dart';
import '../utils/constants.dart';
import '../utils/exceptions.dart';
import '../workflows/ensure_cache.workflow.dart';
import 'base_command.dart';

Expand All @@ -23,7 +24,7 @@ class FlutterCommand extends BaseCommand {
@override
Future<int> run() async {
final version = ProjectService.fromContext.findVersion();
final args = [...argResults!.arguments];
final args = [...?argResults?.arguments];

CacheFlutterVersion? cacheVersion;

Expand Down Expand Up @@ -56,6 +57,7 @@ class FlutterCommand extends BaseCommand {
// Running null will default to flutter version on paths
}
final results = await runFlutter(args, version: cacheVersion);

return results.exitCode;
}
}
21 changes: 11 additions & 10 deletions lib/src/commands/global_command.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import 'package:fvm/constants.dart';
import 'package:fvm/src/models/cache_flutter_version_model.dart';
import 'package:fvm/src/services/global_version_service.dart';
import 'package:fvm/src/services/logger_service.dart';
import 'package:fvm/src/services/project_service.dart';
import 'package:fvm/src/utils/console_utils.dart';
import 'package:fvm/src/utils/context.dart';
import 'package:fvm/src/utils/helpers.dart';
import 'package:fvm/src/utils/which.dart';
import '../utils/constants.dart';
import '../models/cache_flutter_version_model.dart';
import '../services/global_version_service.dart';
import '../services/logger_service.dart';
import '../services/project_service.dart';
import '../utils/console_utils.dart';
import '../utils/context.dart';
import '../utils/helpers.dart';
import '../utils/which.dart';
import 'package:mason_logger/mason_logger.dart';
import 'package:tint/tint.dart';

Expand All @@ -32,7 +32,7 @@ class GlobalCommand extends BaseCommand {
// Show chooser if not version is provided
if (argResults!.rest.isEmpty) {
final versions = await CacheService.fromContext.getAllVersions();
version = await cacheVersionSelector(versions);
version = cacheVersionSelector(versions);
}

// Get first arg if it was not empty
Expand Down Expand Up @@ -97,6 +97,7 @@ class GlobalCommand extends BaseCommand {
)
..info('Run the command outside of the IDE to verify.');
}

return ExitCode.success.code;
}

Expand Down
Loading
Loading