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

Add Analysis Options and Format All Files #284

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pubspec.lock
doc/api/

# The .vscode folder contains launch configuration and tasks you configure in
.vscode/
# .vscode/

# Avoid committing generated Javascript files:
*.dart.js
Expand Down
8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"[dart]": {
"editor.formatOnSave": true
},
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
}
}
34 changes: 29 additions & 5 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,34 @@
# Include option is buggy:
# https://github.com/flutter/flutter/issues/62591
# In case the include issue gets fixed, lines below INCLUDE_FIX
# can be removed

include: package:lints/recommended.yaml

linter:
rules:
constant_identifier_names: false
always_use_package_imports: true
always_declare_return_types: true
avoid_print: true
prefer_is_empty: true
prefer_is_not_empty: true
prefer_is_not_operator: true
prefer_single_quotes: true
require_trailing_commas: true
unnecessary_overrides: false
avoid_function_literals_in_foreach_calls: false
unrelated_type_equality_checks: true

analyzer:
errors:
always_use_package_imports: error
always_declare_return_types: error
avoid_init_to_null: error
avoid_print: error
prefer_const_constructors: error
prefer_const_constructors_in_immutables: error
prefer_const_literals_to_create_immutables: error
prefer_is_empty: error
prefer_is_not_empty: error
prefer_is_not_operator: error
prefer_single_quotes: error
require_trailing_commas: error
unrelated_type_equality_checks: error
unused_element: error
unused_local_variable: error
6 changes: 3 additions & 3 deletions lib/commands/commands_list.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'impl/commads_export.dart';
import 'interface/command.dart';
import 'package:get_cli/commands/impl/commads_export.dart';
import 'package:get_cli/commands/interface/command.dart';

final List<Command> commands = [
CommandParent(
Expand All @@ -10,7 +10,7 @@ final List<Command> commands = [
CreateProjectCommand(),
CreateProviderCommand(),
CreateScreenCommand(),
CreateViewCommand()
CreateViewCommand(),
],
['-c'],
),
Expand Down
2 changes: 1 addition & 1 deletion lib/commands/impl/args_mixin.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:http/http.dart';
import 'package:recase/recase.dart';

import '../../core/generator.dart';
import 'package:get_cli/core/generator.dart';

mixin ArgsMixin {
final List<String> _args = GetCli.arguments;
Expand Down
57 changes: 33 additions & 24 deletions lib/commands/impl/create/controller/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ import 'dart:io';
import 'package:http/http.dart';
import 'package:path/path.dart';

import '../../../../common/utils/pubspec/pubspec_utils.dart';
import '../../../../core/internationalization.dart';
import '../../../../core/locales.g.dart';
import '../../../../core/structure.dart';
import '../../../../exception_handler/exceptions/cli_exception.dart';
import '../../../../functions/binding/add_dependencies.dart';
import '../../../../functions/binding/find_bindings.dart';
import '../../../../functions/create/create_single_file.dart';
import '../../../../functions/is_url/is_url.dart';
import '../../../../functions/replace_vars/replace_vars.dart';
import '../../../../samples/impl/get_controller.dart';
import '../../../interface/command.dart';
import 'package:get_cli/common/utils/pubspec/pubspec_utils.dart';
import 'package:get_cli/core/internationalization.dart';
import 'package:get_cli/core/locales.g.dart';
import 'package:get_cli/core/structure.dart';
import 'package:get_cli/exception_handler/exceptions/cli_exception.dart';
import 'package:get_cli/functions/binding/add_dependencies.dart';
import 'package:get_cli/functions/binding/find_bindings.dart';
import 'package:get_cli/functions/create/create_single_file.dart';
import 'package:get_cli/functions/is_url/is_url.dart';
import 'package:get_cli/functions/replace_vars/replace_vars.dart';
import 'package:get_cli/samples/impl/get_controller.dart';
import 'package:get_cli/commands/interface/command.dart';

/// This command is a controller with the template:
///```
Expand All @@ -37,24 +37,31 @@ class CreateControllerCommand extends Command {
if (args.length > 2) {
var unnecessaryParameter = args.skip(2).toList();
throw CliException(
LocaleKeys.error_unnecessary_parameter.trArgsPlural(
LocaleKeys.error_unnecessary_parameter_plural,
unnecessaryParameter.length,
[unnecessaryParameter.toString()],
),
codeSample: codeSample);
LocaleKeys.error_unnecessary_parameter.trArgsPlural(
LocaleKeys.error_unnecessary_parameter_plural,
unnecessaryParameter.length,
[unnecessaryParameter.toString()],
),
codeSample: codeSample,
);
}
return true;
}

@override
Future<void> execute() async {
return createController(name,
withArgument: withArgument, onCommand: onCommand);
return createController(
name,
withArgument: withArgument,
onCommand: onCommand,
);
}

Future<void> createController(String name,
{String withArgument = '', String onCommand = ''}) async {
Future<void> createController(
String name, {
String withArgument = '',
String onCommand = '',
}) async {
var sample = ControllerSample('', name, PubspecUtils.isServerProject);
if (withArgument.isNotEmpty) {
if (isURL(withArgument)) {
Expand All @@ -64,7 +71,8 @@ class CreateControllerCommand extends Command {
sample.customContent = replaceVars(content, name);
} else {
throw CliException(
LocaleKeys.error_failed_to_connect.trArgs([withArgument]));
LocaleKeys.error_failed_to_connect.trArgs([withArgument]),
);
}
} else {
var file = File(withArgument);
Expand All @@ -73,7 +81,8 @@ class CreateControllerCommand extends Command {
sample.customContent = replaceVars(content, name);
} else {
throw CliException(
LocaleKeys.error_no_valid_file_or_url.trArgs([withArgument]));
LocaleKeys.error_no_valid_file_or_url.trArgs([withArgument]),
);
}
}
}
Expand Down
27 changes: 13 additions & 14 deletions lib/commands/impl/create/page/page.dart
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
import 'dart:io';


import 'package:dcli/dcli.dart';
import 'package:recase/recase.dart';

import '../../../../common/menu/menu.dart';
import '../../../../common/utils/logger/log_utils.dart';
import '../../../../common/utils/pubspec/pubspec_utils.dart';
import '../../../../core/generator.dart';
import '../../../../core/internationalization.dart';
import '../../../../core/locales.g.dart';
import '../../../../core/structure.dart';
import '../../../../functions/create/create_single_file.dart';
import '../../../../functions/routes/get_add_route.dart';
import '../../../../samples/impl/get_binding.dart';
import '../../../../samples/impl/get_controller.dart';
import '../../../../samples/impl/get_view.dart';
import '../../../interface/command.dart';
import 'package:get_cli/common/menu/menu.dart';
import 'package:get_cli/common/utils/logger/log_utils.dart';
import 'package:get_cli/common/utils/pubspec/pubspec_utils.dart';
import 'package:get_cli/core/generator.dart';
import 'package:get_cli/core/internationalization.dart';
import 'package:get_cli/core/locales.g.dart';
import 'package:get_cli/core/structure.dart';
import 'package:get_cli/functions/create/create_single_file.dart';
import 'package:get_cli/functions/routes/get_add_route.dart';
import 'package:get_cli/samples/impl/get_binding.dart';
import 'package:get_cli/samples/impl/get_controller.dart';
import 'package:get_cli/samples/impl/get_view.dart';
import 'package:get_cli/commands/interface/command.dart';

/// The command create a Binding and Controller page and view
class CreatePageCommand extends Command {
Expand Down
67 changes: 40 additions & 27 deletions lib/commands/impl/create/project/project.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,29 @@ import 'package:dcli/dcli.dart';
import 'package:path/path.dart' as p;
import 'package:recase/recase.dart';

import '../../../../common/menu/menu.dart';
import '../../../../common/utils/pubspec/pubspec_utils.dart';
import '../../../../common/utils/shell/shel.utils.dart';
import '../../../../core/internationalization.dart';
import '../../../../core/locales.g.dart';
import '../../../../core/structure.dart';
import '../../../../samples/impl/analysis_options.dart';
import '../../../interface/command.dart';
import '../../init/flutter/init.dart';
import '../../init/get_server/get_server_command.dart';
import 'package:get_cli/common/menu/menu.dart';
import 'package:get_cli/common/utils/pubspec/pubspec_utils.dart';
import 'package:get_cli/common/utils/shell/shel.utils.dart';
import 'package:get_cli/core/internationalization.dart';
import 'package:get_cli/core/locales.g.dart';
import 'package:get_cli/core/structure.dart';
import 'package:get_cli/samples/impl/analysis_options.dart';
import 'package:get_cli/commands/interface/command.dart';
import 'package:get_cli/commands/impl/init/flutter/init.dart';
import 'package:get_cli/commands/impl/init/get_server/get_server_command.dart';

class CreateProjectCommand extends Command {
@override
String get commandName => 'project';
@override
Future<void> execute() async {
final menu = Menu([
'Flutter Project',
'Get Server',
], title: 'Select which type of project you want to create ?');
final menu = Menu(
[
'Flutter Project',
'Get Server',
],
title: 'Select which type of project you want to create ?',
);
final result = menu.choose();
String? nameProject = name;
if (name == '.') {
Expand All @@ -34,7 +37,8 @@ class CreateProjectCommand extends Command {
}

var path = Structure.replaceAsExpected(
path: Directory.current.path + p.separator + nameProject.snakeCase);
path: Directory.current.path + p.separator + nameProject.snakeCase,
);
await Directory(path).create(recursive: true);

Directory.current = path;
Expand Down Expand Up @@ -65,10 +69,13 @@ class CreateProjectCommand extends Command {

var androidLang = androidResult.index == 0 ? 'kotlin' : 'java';

final linterMenu = Menu([
'Yes',
'No',
], title: LocaleKeys.ask_use_linter.tr);
final linterMenu = Menu(
[
'Yes',
'No',
],
title: LocaleKeys.ask_use_linter.tr,
);
final linterResult = linterMenu.choose();

await ShellUtils.flutterCreate(path, org, iosLang, androidLang);
Expand All @@ -78,17 +85,23 @@ class CreateProjectCommand extends Command {
switch (linterResult.index) {
case 0:
if (PubspecUtils.isServerProject) {
await PubspecUtils.addDependencies('lints',
isDev: true, runPubGet: true);
await PubspecUtils.addDependencies(
'lints',
isDev: true,
runPubGet: true,
);
AnalysisOptionsSample(
include: 'include: package:lints/recommended.yaml')
.create();
include: 'include: package:lints/recommended.yaml',
).create();
} else {
await PubspecUtils.addDependencies('flutter_lints',
isDev: true, runPubGet: true);
await PubspecUtils.addDependencies(
'flutter_lints',
isDev: true,
runPubGet: true,
);
AnalysisOptionsSample(
include: 'include: package:flutter_lints/flutter.yaml')
.create();
include: 'include: package:flutter_lints/flutter.yaml',
).create();
}
break;

Expand Down
20 changes: 13 additions & 7 deletions lib/commands/impl/create/provider/provider.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import '../../../../core/internationalization.dart';
import '../../../../core/locales.g.dart';
import '../../../../functions/create/create_single_file.dart';
import '../../../../samples/impl/get_provider.dart';
import '../../../interface/command.dart';
import 'package:get_cli/core/internationalization.dart';
import 'package:get_cli/core/locales.g.dart';
import 'package:get_cli/functions/create/create_single_file.dart';
import 'package:get_cli/samples/impl/get_provider.dart';
import 'package:get_cli/commands/interface/command.dart';

class CreateProviderCommand extends Command {
@override
String get commandName => 'provider';
@override
Future<void> execute() async {
var name = this.name;
handleFileCreate(name, 'provider', onCommand, onCommand.isNotEmpty,
ProviderSample(name), onCommand.isNotEmpty ? 'providers' : '');
handleFileCreate(
name,
'provider',
onCommand,
onCommand.isNotEmpty,
ProviderSample(name),
onCommand.isNotEmpty ? 'providers' : '',
);
}

@override
Expand Down
Loading