Skip to content

Commit 9ab15c1

Browse files
committed
analyzer cleanups
1 parent 86ae22a commit 9ab15c1

9 files changed

+42
-56
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Create [Google Sheets API credentials](doc/Authentication.md) either by using Cl
4949
1. Add gsheet_to_arb dev dependency to the pubspec.yaml
5050
```yaml
5151
dev_dependencies:
52-
gsheet_to_arb: ^0.0.6
52+
gsheet_to_arb: ^0.1.0
5353
```
5454
5555
2. Updated dependencies

analysis_options.yaml

+1-14
Original file line numberDiff line numberDiff line change
@@ -1,14 +1 @@
1-
analyzer:
2-
# exclude:
3-
# - path/to/excluded/files/**
4-
5-
# Lint rules and documentation, see http://dart-lang.github.io/linter/lints
6-
linter:
7-
rules:
8-
- cancel_subscriptions
9-
- hash_and_equals
10-
- iterable_contains_unrelated_type
11-
- list_remove_unrelated_type
12-
- test_types_in_equals
13-
- unrelated_type_equality_checks
14-
- valid_regexps
1+
include: package:pedantic/analysis_options.yaml

bin/arb_to_dart.dart

+7-7
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ import 'dart:io';
1111
import 'package:args/args.dart';
1212
import 'package:gsheet_to_arb/gsheet_to_arb.dart';
1313

14-
main(List<String> args) async {
15-
var parser = new ArgParser();
16-
var configFilePath = "./gsheet_to_arb.yaml";
14+
void main(List<String> args) async {
15+
var parser = ArgParser();
16+
var configFilePath = './gsheet_to_arb.yaml';
1717

18-
parser.addOption("config",
18+
parser.addOption('config',
1919
defaultsTo: configFilePath,
2020
callback: (x) => configFilePath = x,
2121
help: 'config yaml file name');
2222

23-
parser.addFlag("help", help: 'show helps');
23+
parser.addFlag('help', help: 'show helps');
2424

2525
parser.parse(args);
26-
if (args.length == 0) {
26+
if (args.isEmpty) {
2727
Log.i('Converts ARB file to Dart i18n');
2828
Log.i('Usage: gsheet_to_arb [options]');
2929
Log.i(parser.usage);
@@ -33,7 +33,7 @@ main(List<String> args) async {
3333
final config = PluginConfigHelper().fromYamlFile(configFilePath);
3434
final serializer = ArbSerializer();
3535
final document =
36-
serializer.loadArbDocument("${config.outputDirectoryPath}/intl_en.arb");
36+
serializer.loadArbDocument('${config.outputDirectoryPath}/intl_en.arb');
3737
final localizationFileName = config.localizationFileName;
3838
final generator = TranslationsGenerator();
3939
generator.buildTranslations(

bin/import.dart

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ import 'package:args/args.dart';
1212
import 'package:gsheet_to_arb/gsheet_to_arb.dart';
1313
import 'package:gsheet_to_arb/src/utils/log.dart';
1414

15-
main(List<String> args) async {
16-
var parser = new ArgParser();
17-
var configFilePath = "./gsheet_to_arb.yaml";
15+
void main(List<String> args) async {
16+
var parser = ArgParser();
17+
var configFilePath = './gsheet_to_arb.yaml';
1818

19-
parser.addOption("config",
19+
parser.addOption('config',
2020
defaultsTo: configFilePath,
2121
callback: (x) => configFilePath = x,
2222
help: 'config yaml file name');
2323

2424
parser.parse(args);
25-
if (args.length == 0) {
25+
if (args.isEmpty) {
2626
Log.i('Imports ARB file from exisiting GSheet document');
2727
Log.i('Usage: gsheet_to_arb [options]');
2828
Log.i(parser.usage);

lib/gsheet_to_arb.dart

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@
99
/// More dartdocs go here.
1010
library gsheet_to_arb;
1111

12-
export 'package:gsheet_to_arb/src/sheet/sheet_parser.dart';
13-
1412
export 'src/arb/arb_generator.dart';
1513
export 'src/arb/arb_serializer.dart';
1614
export 'src/arb/intl_translation_helper.dart';
17-
export 'src/arb_to_class_generator.dart';
1815
export 'src/config/plugin_config.dart';
1916
export 'src/config/plugin_config_helper.dart';
2017
export 'src/utils/log.dart';
18+
export 'src/gsheet/sheet_parser.dart';
19+
export 'src/output/arb_to_class_generator.dart';

lib/src/arb/intl_translation_helper.dart

+11-12
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import 'package:path/path.dart' as path;
1616

1717
class IntlTranslationHelper {
1818
void aaa(String outputDirectoryPath, String localizationFileName) {
19-
var extraction = new MessageExtraction();
20-
var generation = new MessageGeneration();
19+
var extraction = MessageExtraction();
20+
var generation = MessageGeneration();
2121

2222
generation.generatedFilePrefix = "_";
2323

@@ -33,27 +33,26 @@ class IntlTranslationHelper {
3333
var targetDir = outputDirectoryPath;
3434

3535
extraction.suppressWarnings = true;
36-
var allMessages =
37-
dartFiles.map((each) => extraction.parseFile(new File(each)));
36+
var allMessages = dartFiles.map((each) => extraction.parseFile(File(each)));
3837

39-
messages = new Map();
38+
messages = Map();
4039
for (var eachMap in allMessages) {
4140
eachMap.forEach(
4241
(key, value) => messages.putIfAbsent(key, () => []).add(value));
4342
}
4443
for (var arg in jsonFiles) {
45-
var file = new File(arg);
44+
var file = File(arg);
4645
generateLocaleFile(file, targetDir, generation);
4746
}
4847

49-
var mainImportFile = new File(path.join(
48+
var mainImportFile = File(path.join(
5049
targetDir, '${generation.generatedFilePrefix}messages_all.dart'));
5150
mainImportFile.writeAsStringSync(generation.generateMainImportFile());
5251
}
5352

54-
final pluralAndGenderParser = new IcuParser().message;
53+
final pluralAndGenderParser = IcuParser().message;
5554

56-
final plainParser = new IcuParser().nonIcuMessage;
55+
final plainParser = IcuParser().nonIcuMessage;
5756

5857
/// Keeps track of all the messages we have processed so far, keyed by message
5958
/// name.
@@ -70,15 +69,15 @@ class IntlTranslationHelper {
7069
File file, String targetDir, MessageGeneration generation) {
7170
var src = file.readAsStringSync();
7271
var data = jsonDecoder.decode(src);
73-
var locale = data["@@locale"] ?? data["_locale"];
72+
var locale = data['@@locale'] ?? data['_locale'];
7473
if (locale == null) {
7574
// Get the locale from the end of the file name. This assumes that the file
7675
// name doesn't contain any underscores except to begin the language tag
7776
// and to separate language from country. Otherwise we can't tell if
7877
// my_file_fr.arb is locale "fr" or "file_fr".
7978
var name = path.basenameWithoutExtension(file.path);
80-
locale = name.split("_").skip(1).join("_");
81-
Log.i("No @@locale or _locale field found in $name, "
79+
locale = name.split('_').skip(1).join('_');
80+
Log.i('No @@locale or _locale field found in $name, '
8281
"assuming '$locale' based on the file name.");
8382
}
8483
generation.allLocales.add(locale);

lib/src/config/plugin_config.dart

+5-5
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ class PluginConfigRoot {
3030
///
3131
@JsonSerializable()
3232
class PluginConfig {
33-
@JsonKey(name: 'output_directory', defaultValue: "lib/src/i18n")
33+
@JsonKey(name: 'output_directory', defaultValue: 'lib/src/i18n')
3434
String outputDirectoryPath;
3535

36-
@JsonKey(name: 'arb_file_prefix', defaultValue: "intl")
36+
@JsonKey(name: 'arb_file_prefix', defaultValue: 'intl')
3737
String arbFilePrefix;
3838

39-
@JsonKey(name: 'localization_file_name', defaultValue: "S")
39+
@JsonKey(name: 'localization_file_name', defaultValue: 'S')
4040
String localizationFileName;
4141

4242
@JsonKey(name: 'gsheet', nullable: false)
@@ -61,10 +61,10 @@ class GoogleSheetConfig {
6161
@JsonKey(name: 'document_id')
6262
String documentId;
6363

64-
@JsonKey(name: 'sheet_id', defaultValue: "0")
64+
@JsonKey(name: 'sheet_id', defaultValue: '0')
6565
String sheetId;
6666

67-
@JsonKey(name: 'category_prefix', defaultValue: "# ")
67+
@JsonKey(name: 'category_prefix', defaultValue: '# ')
6868
String categoryPrefix;
6969

7070
GoogleSheetConfig(

lib/src/gsheet/sheet_parser.dart

+9-8
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ class SheetParser {
1818

1919
SheetParser({this.auth, this.categoryPrefix});
2020

21-
var _languages = List<ArbDocumentBuilder>();
22-
var _scopes = [SheetsApi.SpreadsheetsReadonlyScope];
21+
final _languages = <ArbDocumentBuilder>[];
22+
final _scopes = [SheetsApi.SpreadsheetsReadonlyScope];
2323

2424
Future<ArbBundle> parseSheet(String documentId) async {
2525
var authClient = await _authClient(auth);
@@ -38,17 +38,18 @@ class SheetParser {
3838
auth.serviceAccountKey.privateKey);
3939
authClient = await clientViaServiceAccount(accountCredentials, _scopes);
4040
} else if (auth.oauthClientId != null) {
41-
var id = new ClientId(
41+
var id = ClientId(
4242
auth.oauthClientId.clientId, auth.oauthClientId.clientSecret);
4343
authClient = await clientViaUserConsent(id, _scopes, _prompt);
4444
}
4545
return authClient;
4646
}
4747

4848
void _prompt(String url) {
49-
Log.i("Please go to the following URL and grant Google Spreasheet access:");
50-
Log.i(" => $url");
51-
Log.i("");
49+
Log.i(
50+
'Please go to the following URL and grant Google Spreadsheet access:');
51+
Log.i(' => $url');
52+
Log.i('');
5253
}
5354

5455
Future<ArbBundle> _handleSheetsAuth(
@@ -65,7 +66,7 @@ class SheetParser {
6566
}
6667

6768
ArbBundle _handleSpreadsheet(Spreadsheet spreadsheet) {
68-
Log.i("Opening ${spreadsheet.spreadsheetUrl}");
69+
Log.i('Opening ${spreadsheet.spreadsheetUrl}');
6970

7071
var sheet = spreadsheet.sheets[0];
7172
var rows = sheet.data[0].rowData;
@@ -89,7 +90,7 @@ class SheetParser {
8990
// Skip header row
9091
var firstTranslationsRow = 1;
9192

92-
var currentCategory = "";
93+
var currentCategory = '';
9394

9495
for (var i = firstTranslationsRow; i < rows.length; i++) {
9596
var row = rows[i];

pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: gsheet_to_arb
2-
version: 0.0.8
2+
version: 0.1.0
33
author: Marcin Marek Gocał <[email protected]>
44
description: Imports Application Resource Bundle (ARB) from Google Sheets documents
55

0 commit comments

Comments
 (0)