Skip to content

feature: no longer generate new, const #276

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

Merged
merged 5 commits into from
Aug 7, 2018
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
48 changes: 24 additions & 24 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,63 +14,63 @@ addons:
jobs:
include:
- stage: analyzer_and_format
name: "SDK: dev - DIR: example - TASKS: dartfmt -n --set-exit-if-changed ."
name: "SDK: stable - DIR: example - TASKS: dartfmt -n --set-exit-if-changed ."
script: ./tool/travis.sh dartfmt
env: PKG="example"
dart: dev
dart: stable
- stage: analyzer_and_format
name: "SDK: dev - DIR: example - TASKS: dartanalyzer --fatal-infos --fatal-warnings ."
script: ./tool/travis.sh dartanalyzer
name: "SDK: stable - DIR: example - TASKS: dartanalyzer --fatal-warnings ."
script: ./tool/travis.sh dartanalyzer_0
env: PKG="example"
dart: dev
dart: stable
- stage: unit_test
name: "SDK: dev - DIR: example - TASKS: pub run test --run-skipped"
name: "SDK: stable - DIR: example - TASKS: pub run test --run-skipped"
script: ./tool/travis.sh test_0
env: PKG="example"
dart: dev
dart: stable
- stage: analyzer_and_format
name: "SDK: dev - DIR: json_annotation - TASKS: dartfmt -n --set-exit-if-changed ."
name: "SDK: stable - DIR: json_annotation - TASKS: dartfmt -n --set-exit-if-changed ."
script: ./tool/travis.sh dartfmt
env: PKG="json_annotation"
dart: dev
dart: stable
- stage: analyzer_and_format
name: "SDK: dev - DIR: json_annotation - TASKS: dartanalyzer --fatal-infos --fatal-warnings ."
script: ./tool/travis.sh dartanalyzer
name: "SDK: stable - DIR: json_annotation - TASKS: dartanalyzer --fatal-infos --fatal-warnings ."
script: ./tool/travis.sh dartanalyzer_1
env: PKG="json_annotation"
dart: dev
dart: stable
- stage: analyzer_and_format
name: "SDK: dev - DIR: json_serializable - TASKS: dartfmt -n --set-exit-if-changed ."
name: "SDK: stable - DIR: json_serializable - TASKS: dartfmt -n --set-exit-if-changed ."
script: ./tool/travis.sh dartfmt
env: PKG="json_serializable"
dart: dev
dart: stable
- stage: analyzer_and_format
name: "SDK: dev - DIR: json_serializable - TASKS: dartanalyzer --fatal-infos --fatal-warnings ."
script: ./tool/travis.sh dartanalyzer
name: "SDK: stable - DIR: json_serializable - TASKS: dartanalyzer --fatal-infos --fatal-warnings ."
script: ./tool/travis.sh dartanalyzer_1
env: PKG="json_serializable"
dart: dev
dart: stable
- stage: unit_test
name: "SDK: dev - DIR: json_serializable - TASKS: pub run test"
name: "SDK: stable - DIR: json_serializable - TASKS: pub run test"
script: ./tool/travis.sh test_1
env: PKG="json_serializable"
dart: dev
dart: stable
- stage: unit_test
name: "SDK: dev - DIR: json_serializable - TASKS: pub run test --run-skipped test/ensure_build_test.dart"
name: "SDK: stable - DIR: json_serializable - TASKS: pub run test --run-skipped test/ensure_build_test.dart"
script: ./tool/travis.sh test_2
env: PKG="json_serializable"
dart: dev
dart: stable
- stage: unit_test
name: "SDK: dev - DIR: json_serializable - TASKS: pub run build_runner test -- -p chrome"
name: "SDK: stable - DIR: json_serializable - TASKS: pub run build_runner test -- -p chrome"
script: ./tool/travis.sh command
env: PKG="json_serializable"
dart: dev
dart: stable

stages:
- analyzer_and_format
- unit_test

# Only building master means that we don't run two builds for each pull request.
branches:
only: [master,0_5_x]
only: [master]

cache:
directories:
Expand Down
3 changes: 3 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,11 @@ linter:
- type_init_formals
- unawaited_futures
- unnecessary_brace_in_string_interps
# Waiting on https://github.com/dart-lang/test/issues/915
#- unnecessary_const
- unnecessary_getters_setters
- unnecessary_lambdas
- unnecessary_new
- unnecessary_null_aware_assignments
- unnecessary_statements
- unnecessary_this
Expand Down
6 changes: 4 additions & 2 deletions example/.mono_repo.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# See https://github.com/dart-lang/mono_repo for details
dart:
- dev
- stable

stages:
- analyzer_and_format:
- dartfmt
- dartanalyzer: --fatal-infos --fatal-warnings .
# Skipping --fatal-infos until we can regenerate this package with publish
# json_serializable
- dartanalyzer: --fatal-warnings .
- unit_test:
# Run the tests -- include the default-skipped presubmit tests
- test: --run-skipped
4 changes: 2 additions & 2 deletions example/lib/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ class Order {
}

Duration _durationFromMillseconds(int milliseconds) =>
new Duration(milliseconds: milliseconds);
Duration(milliseconds: milliseconds);
int _durationToMilliseconds(Duration duration) => duration.inMilliseconds;

DateTime _dateTimeFromEpochUs(int us) =>
new DateTime.fromMicrosecondsSinceEpoch(us);
DateTime.fromMicrosecondsSinceEpoch(us);
int _dateTimeToEpochUs(DateTime dateTime) => dateTime.microsecondsSinceEpoch;

@JsonSerializable()
Expand Down
8 changes: 4 additions & 4 deletions example/test/ensure_build_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void main() {
var currentDir = Directory.current.resolveSymbolicLinksSync();

if (!p.equals(p.join(pkgRoot, 'example'), currentDir)) {
throw new StateError('Expected the git root ($pkgRoot) '
throw StateError('Expected the git root ($pkgRoot) '
'to match the current directory ($currentDir).');
}
});
Expand All @@ -33,14 +33,14 @@ void main() {
var result = _runProc('pub',
['run', 'build_runner', 'build', '--delete-conflicting-outputs']);
expect(result,
contains(new RegExp(r'\[INFO\] Succeeded after \S+ with \d+ outputs')));
contains(RegExp(r'\[INFO\] Succeeded after \S+ with \d+ outputs')));

// 3 - get a list of modified `.g.dart` files - should still be empty
expect(_changedGeneratedFiles(), isEmpty);
});
}

final _whitespace = new RegExp(r'\s');
final _whitespace = RegExp(r'\s');

Set<String> _changedGeneratedFiles() {
var output = _runProc('git', ['status', '--porcelain']);
Expand All @@ -55,7 +55,7 @@ String _runProc(String proc, List<String> args) {
var result = Process.runSync(proc, args);

if (result.exitCode != 0) {
throw new ProcessException(
throw ProcessException(
proc, args, result.stderr as String, result.exitCode);
}

Expand Down
8 changes: 3 additions & 5 deletions example/test/example_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ import 'package:test/test.dart';

void main() {
test('JsonSerializable', () {
final person = new Person('Inigo', 'Montoya', new DateTime(1560, 5, 5))
..orders = [
new Order(new DateTime.now())..item = (new Item()..count = 42)
];
final person = Person('Inigo', 'Montoya', DateTime(1560, 5, 5))
..orders = [Order(DateTime.now())..item = (Item()..count = 42)];

final personJson = _encode(person);

final person2 =
new Person.fromJson(json.decode(personJson) as Map<String, dynamic>);
Person.fromJson(json.decode(personJson) as Map<String, dynamic>);

expect(person.firstName, person2.firstName);
expect(person.lastName, person2.lastName);
Expand Down
2 changes: 1 addition & 1 deletion example/test/readme_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ void main() {

void _expect(String fileName) {
test(fileName, () {
final file = new File(fileName);
final file = File(fileName);
expect(file.readAsStringSync(), contains(_pubspecContent));
});
}
Expand Down
2 changes: 1 addition & 1 deletion json_annotation/.mono_repo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# See https://github.com/dart-lang/mono_repo for details
dart:
- dev
- stable

stages:
- analyzer_and_format:
Expand Down
6 changes: 3 additions & 3 deletions json_annotation/lib/src/allowed_keys_helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ void $checkKeys(Map map,
var invalidKeys =
map.keys.cast<String>().where((k) => !allowedKeys.contains(k)).toList();
if (invalidKeys.isNotEmpty) {
throw new UnrecognizedKeysException(invalidKeys, map, allowedKeys);
throw UnrecognizedKeysException(invalidKeys, map, allowedKeys);
}
}

if (requiredKeys != null) {
var missingKeys = requiredKeys.where((k) => !map.keys.contains(k)).toList();
if (missingKeys.isNotEmpty) {
throw new MissingRequiredKeysException(missingKeys, map);
throw MissingRequiredKeysException(missingKeys, map);
}
}

Expand All @@ -34,7 +34,7 @@ void $checkKeys(Map map,
.toList();

if (nullValuedKeys.isNotEmpty) {
throw new DisallowedNullValueException(nullValuedKeys, map);
throw DisallowedNullValueException(nullValuedKeys, map);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions json_annotation/lib/src/checked_helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ T $checkedNew<T>(String className, Map map, T constructor(),
} else if (error is DisallowedNullValueException) {
key = error.keysWithNullValues.first;
}
throw new CheckedFromJsonException._(error, stack, map, key,
throw CheckedFromJsonException._(error, stack, map, key,
className: className);
}
}
Expand All @@ -43,7 +43,7 @@ T $checkedConvert<T>(Map map, String key, T castFunc(Object value)) {
} on CheckedFromJsonException {
rethrow;
} catch (error, stack) {
throw new CheckedFromJsonException._(error, stack, map, key);
throw CheckedFromJsonException._(error, stack, map, key);
}
}

Expand Down
12 changes: 6 additions & 6 deletions json_annotation/lib/src/wrapper_helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,30 @@ abstract class $JsonMapWrapper extends UnmodifiableMapBase<String, dynamic> {}
/// Should not be used directly.
Map<String, dynamic> $wrapMap<K, V>(
Map<K, V> source, dynamic converter(V key)) =>
new _MappingMap(source, converter);
_MappingMap(source, converter);

/// Helper function used in generated code when
/// `JsonSerializableGenerator.useWrappers` is `true`.
///
/// Should not be used directly.
Map<String, dynamic> $wrapMapHandleNull<K, V>(
Map<K, V> source, dynamic converter(V key)) =>
source == null ? null : new _MappingMap(source, converter);
source == null ? null : _MappingMap(source, converter);

/// Helper function used in generated code when
/// `JsonSerializableGenerator.useWrappers` is `true`.
///
/// Should not be used directly.
List<dynamic> $wrapList<T>(List<T> source, dynamic converter(T key)) =>
new _MappingList(source, converter);
_MappingList(source, converter);

/// Helper function used in generated code when
/// `JsonSerializableGenerator.useWrappers` is `true`.
///
/// Should not be used directly.
List<dynamic> $wrapListHandleNull<T>(
List<T> source, dynamic converter(T key)) =>
source == null ? null : new _MappingList(source, converter);
source == null ? null : _MappingList(source, converter);

typedef dynamic _Convert<S>(S value);

Expand All @@ -53,13 +53,13 @@ class _MappingList<S> extends ListBase<dynamic> {
dynamic operator [](int index) => _converter(_source[index]);

@override
operator []=(int index, dynamic value) => throw new UnsupportedError('');
operator []=(int index, dynamic value) => throw UnsupportedError('');

@override
int get length => _source.length;

@override
set length(int value) => throw new UnsupportedError('');
set length(int value) => throw UnsupportedError('');
}

class _MappingMap<K, V> extends UnmodifiableMapBase<String, dynamic> {
Expand Down
2 changes: 1 addition & 1 deletion json_annotation/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: json_annotation
version: 1.0.0
version: 1.0.1-dev
description: >-
Classes and helper functions that support JSON code generation via the
`json_serializable` package.
Expand Down
2 changes: 1 addition & 1 deletion json_serializable/.mono_repo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# See https://github.com/dart-lang/mono_repo for details
dart:
- dev
- stable

stages:
- analyzer_and_format:
Expand Down
4 changes: 4 additions & 0 deletions json_serializable/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.1.0

* Explicit `new` and `const` are no longer generated.

## 1.0.0

* **BREAKING** By default, code generated to support `toJson` now creates
Expand Down
2 changes: 1 addition & 1 deletion json_serializable/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Building creates the corresponding part `example.g.dart`:
part of 'example.dart';

Person _$PersonFromJson(Map<String, dynamic> json) {
return new Person(
return Person(
firstName: json['firstName'] as String,
lastName: json['lastName'] as String,
dateOfBirth: DateTime.parse(json['dateOfBirth'] as String));
Expand Down
2 changes: 1 addition & 1 deletion json_serializable/example/example.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions json_serializable/lib/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import 'src/json_part_builder.dart';
Builder jsonSerializable(BuilderOptions options) {
// Paranoid copy of options.config - don't assume it's mutable or needed
// elsewhere.
var optionsMap = new Map<String, dynamic>.from(options.config);
var optionsMap = Map<String, dynamic>.from(options.config);

var builder = jsonPartBuilder(
useWrappers: optionsMap.remove('use_wrappers') as bool,
Expand All @@ -36,7 +36,7 @@ Builder jsonSerializable(BuilderOptions options) {

if (optionsMap.isNotEmpty) {
if (log == null) {
throw new StateError('Upgrade `build_runner` to at least 0.8.2.');
throw StateError('Upgrade `build_runner` to at least 0.8.2.');
} else {
log.warning('These options were ignored: `$optionsMap`.');
}
Expand Down
Loading