diff --git a/pubspec.yaml b/pubspec.yaml index 9af9300f6..405266a31 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -41,7 +41,6 @@ dev_dependencies: analyzer: ^6.8.0 archive: ^3.1.2 crypto: ^3.0.0 - dart_style: ^3.0.0 dartdoc: ^8.0.14 grinder: ^0.9.0 node_preamble: ^2.0.2 diff --git a/test/double_check_test.dart b/test/double_check_test.dart index c36886443..20fef1d5a 100644 --- a/test/double_check_test.dart +++ b/test/double_check_test.dart @@ -14,6 +14,8 @@ import 'package:pub_semver/pub_semver.dart'; import 'package:pubspec_parse/pubspec_parse.dart'; import 'package:test/test.dart'; +import 'package:sass/src/util/map.dart'; + import '../tool/grind/generate_deprecations.dart' as deprecations; import '../tool/grind/synchronize.dart' as synchronize; @@ -21,26 +23,15 @@ import '../tool/grind/synchronize.dart' as synchronize; void main() { group("up-to-date generated", () { group("synchronized file:", () { - synchronize.sources.forEach((sourcePath, targetPath) { - test(targetPath, () { - if (File(targetPath).readAsStringSync() != - synchronize.synchronizeFile(sourcePath)) { - fail("$targetPath is out-of-date.\n" - "Run `dart run grinder` to update it."); - } - }); - }); - }); - - test("deprecations", () { - var inputText = File(deprecations.yamlPath).readAsStringSync(); - var outputText = File(deprecations.dartPath).readAsStringSync(); - var checksum = sha1.convert(utf8.encode(inputText)); - if (!outputText.contains('// Checksum: $checksum')) { - fail('${deprecations.dartPath} is out-of-date.\n' - 'Run `dart run grinder` to update it.'); + for (var (sourcePath, targetPath) in synchronize.sources.pairs) { + test(targetPath, () => _assertChecksumMatches(sourcePath, targetPath)); } }); + + test( + "deprecations", + () => _assertChecksumMatches( + deprecations.yamlPath, deprecations.dartPath)); }, // Windows sees different bytes than other OSes, possibly because of // newline normalization issues. @@ -182,3 +173,15 @@ void _checkVersionIncrementsAlong( "at its major version as well"); } } + +/// Throws an error if the checksum in [outputPath] doesn't match the hash of +/// the contents of [inputPath]. +void _assertChecksumMatches(String inputPath, String outputPath) { + var inputText = File(inputPath).readAsStringSync(); + var outputText = File(outputPath).readAsStringSync(); + var checksum = sha1.convert(utf8.encode(inputText)); + if (!outputText.contains('// Checksum: $checksum')) { + fail('$outputPath is out-of-date.\n' + 'Run `dart run grinder` to update it.'); + } +} diff --git a/tool/assert-formatted.sh b/tool/assert-formatted.sh deleted file mode 100755 index fe3c4468e..000000000 --- a/tool/assert-formatted.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash -e -# Copyright 2016 Google Inc. Use of this source code is governed by an MIT-style -# license that can be found in the LICENSE file or at -# https://opensource.org/licenses/MIT. - -unformatted=`pub run dart_style:format --fix -n bin/ lib/ tool/ test/` -if [[ -z "$unformatted" ]]; then - exit 0 -else - echo "Files are unformatted:" - echo "$unformatted" - exit 1 -fi diff --git a/tool/grind/generate_deprecations.dart b/tool/grind/generate_deprecations.dart index 5590f465c..cac755a8e 100644 --- a/tool/grind/generate_deprecations.dart +++ b/tool/grind/generate_deprecations.dart @@ -6,9 +6,7 @@ import 'dart:convert'; import 'dart:io'; import 'package:crypto/crypto.dart'; -import 'package:dart_style/dart_style.dart'; import 'package:grinder/grinder.dart'; -import 'package:pub_semver/pub_semver.dart'; import 'package:yaml/yaml.dart'; import 'utils.dart'; @@ -23,10 +21,9 @@ final _blockRegex = @Depends(updateLanguageRepo) void deprecations() { var yamlFile = File(yamlPath); - var dartFile = File(dartPath); var yamlText = yamlFile.readAsStringSync(); var data = loadYaml(yamlText, sourceUrl: yamlFile.uri) as Map; - var dartText = dartFile.readAsStringSync(); + var dartText = File(dartPath).readAsStringSync(); var buffer = StringBuffer('''// START AUTOGENERATED CODE // // DO NOT EDIT. This section was generated from the language repo. @@ -79,7 +76,6 @@ void deprecations() { fail("Couldn't find block for generated code in lib/src/deprecation.dart"); } var newCode = dartText.replaceFirst(_blockRegex, buffer.toString()); - dartFile.writeAsStringSync(DartFormatter( - languageVersion: Version.parse(Platform.version.split(' ').first)) - .format(newCode)); + File(dartPath).writeAsStringSync(newCode); + DartFmt.format(dartPath); } diff --git a/tool/grind/synchronize.dart b/tool/grind/synchronize.dart index 8581eccc8..7da9d83af 100644 --- a/tool/grind/synchronize.dart +++ b/tool/grind/synchronize.dart @@ -13,12 +13,11 @@ import 'package:analyzer/dart/ast/token.dart'; import 'package:analyzer/dart/ast/visitor.dart'; import 'package:collection/collection.dart'; import 'package:crypto/crypto.dart'; -import 'package:dart_style/dart_style.dart'; import 'package:grinder/grinder.dart'; import 'package:path/path.dart' as p; -import 'package:pub_semver/pub_semver.dart'; import 'package:source_span/source_span.dart'; +import 'package:sass/src/util/map.dart'; import 'package:sass/src/util/nullable.dart'; /// The files to compile to synchronous versions. @@ -47,8 +46,10 @@ final _sharedClasses = const ['EvaluateResult']; /// to a synchronous equivalent. @Task('Compile async code to synchronous code.') void synchronize() { - sources.forEach((source, target) => - File(target).writeAsStringSync(synchronizeFile(source))); + for (var (source, target) in sources.pairs) { + File(target).writeAsStringSync(synchronizeFile(source)); + DartFmt.format(target); + } } /// Returns the result of synchronizing [source]. @@ -59,9 +60,7 @@ String synchronizeFile(String source) { parseFile(path: source, featureSet: FeatureSet.latestLanguageVersion()) .unit .accept(visitor); - return DartFormatter( - languageVersion: Version.parse(Platform.version.split(' ').first)) - .format(visitor.result); + return visitor.result; } /// The visitor that traverses the asynchronous parse tree and converts it to