Skip to content

Commit adb7016

Browse files
authored
Merge pull request #2488 from sass/sdk-formatter
Always use the SDK version of the formatter
2 parents 9e6e3bf + 7f2f4af commit adb7016

5 files changed

+30
-46
lines changed

pubspec.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ dev_dependencies:
4141
analyzer: ^6.8.0
4242
archive: ^3.1.2
4343
crypto: ^3.0.0
44-
dart_style: ^3.0.0
4544
dartdoc: ^8.0.14
4645
grinder: ^0.9.0
4746
node_preamble: ^2.0.2

test/double_check_test.dart

+21-18
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,24 @@ import 'package:pub_semver/pub_semver.dart';
1414
import 'package:pubspec_parse/pubspec_parse.dart';
1515
import 'package:test/test.dart';
1616

17+
import 'package:sass/src/util/map.dart';
18+
1719
import '../tool/grind/generate_deprecations.dart' as deprecations;
1820
import '../tool/grind/synchronize.dart' as synchronize;
1921

2022
/// Tests that double-check that everything in the repo looks sensible.
2123
void main() {
2224
group("up-to-date generated", () {
2325
group("synchronized file:", () {
24-
synchronize.sources.forEach((sourcePath, targetPath) {
25-
test(targetPath, () {
26-
if (File(targetPath).readAsStringSync() !=
27-
synchronize.synchronizeFile(sourcePath)) {
28-
fail("$targetPath is out-of-date.\n"
29-
"Run `dart run grinder` to update it.");
30-
}
31-
});
32-
});
33-
});
34-
35-
test("deprecations", () {
36-
var inputText = File(deprecations.yamlPath).readAsStringSync();
37-
var outputText = File(deprecations.dartPath).readAsStringSync();
38-
var checksum = sha1.convert(utf8.encode(inputText));
39-
if (!outputText.contains('// Checksum: $checksum')) {
40-
fail('${deprecations.dartPath} is out-of-date.\n'
41-
'Run `dart run grinder` to update it.');
26+
for (var (sourcePath, targetPath) in synchronize.sources.pairs) {
27+
test(targetPath, () => _assertChecksumMatches(sourcePath, targetPath));
4228
}
4329
});
30+
31+
test(
32+
"deprecations",
33+
() => _assertChecksumMatches(
34+
deprecations.yamlPath, deprecations.dartPath));
4435
},
4536
// Windows sees different bytes than other OSes, possibly because of
4637
// newline normalization issues.
@@ -182,3 +173,15 @@ void _checkVersionIncrementsAlong(
182173
"at its major version as well");
183174
}
184175
}
176+
177+
/// Throws an error if the checksum in [outputPath] doesn't match the hash of
178+
/// the contents of [inputPath].
179+
void _assertChecksumMatches(String inputPath, String outputPath) {
180+
var inputText = File(inputPath).readAsStringSync();
181+
var outputText = File(outputPath).readAsStringSync();
182+
var checksum = sha1.convert(utf8.encode(inputText));
183+
if (!outputText.contains('// Checksum: $checksum')) {
184+
fail('$outputPath is out-of-date.\n'
185+
'Run `dart run grinder` to update it.');
186+
}
187+
}

tool/assert-formatted.sh

-13
This file was deleted.

tool/grind/generate_deprecations.dart

+3-7
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ import 'dart:convert';
66
import 'dart:io';
77

88
import 'package:crypto/crypto.dart';
9-
import 'package:dart_style/dart_style.dart';
109
import 'package:grinder/grinder.dart';
11-
import 'package:pub_semver/pub_semver.dart';
1210
import 'package:yaml/yaml.dart';
1311

1412
import 'utils.dart';
@@ -23,10 +21,9 @@ final _blockRegex =
2321
@Depends(updateLanguageRepo)
2422
void deprecations() {
2523
var yamlFile = File(yamlPath);
26-
var dartFile = File(dartPath);
2724
var yamlText = yamlFile.readAsStringSync();
2825
var data = loadYaml(yamlText, sourceUrl: yamlFile.uri) as Map;
29-
var dartText = dartFile.readAsStringSync();
26+
var dartText = File(dartPath).readAsStringSync();
3027
var buffer = StringBuffer('''// START AUTOGENERATED CODE
3128
//
3229
// DO NOT EDIT. This section was generated from the language repo.
@@ -79,7 +76,6 @@ void deprecations() {
7976
fail("Couldn't find block for generated code in lib/src/deprecation.dart");
8077
}
8178
var newCode = dartText.replaceFirst(_blockRegex, buffer.toString());
82-
dartFile.writeAsStringSync(DartFormatter(
83-
languageVersion: Version.parse(Platform.version.split(' ').first))
84-
.format(newCode));
79+
File(dartPath).writeAsStringSync(newCode);
80+
DartFmt.format(dartPath);
8581
}

tool/grind/synchronize.dart

+6-7
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@ import 'package:analyzer/dart/ast/token.dart';
1313
import 'package:analyzer/dart/ast/visitor.dart';
1414
import 'package:collection/collection.dart';
1515
import 'package:crypto/crypto.dart';
16-
import 'package:dart_style/dart_style.dart';
1716
import 'package:grinder/grinder.dart';
1817
import 'package:path/path.dart' as p;
19-
import 'package:pub_semver/pub_semver.dart';
2018
import 'package:source_span/source_span.dart';
2119

20+
import 'package:sass/src/util/map.dart';
2221
import 'package:sass/src/util/nullable.dart';
2322

2423
/// The files to compile to synchronous versions.
@@ -47,8 +46,10 @@ final _sharedClasses = const ['EvaluateResult'];
4746
/// to a synchronous equivalent.
4847
@Task('Compile async code to synchronous code.')
4948
void synchronize() {
50-
sources.forEach((source, target) =>
51-
File(target).writeAsStringSync(synchronizeFile(source)));
49+
for (var (source, target) in sources.pairs) {
50+
File(target).writeAsStringSync(synchronizeFile(source));
51+
DartFmt.format(target);
52+
}
5253
}
5354

5455
/// Returns the result of synchronizing [source].
@@ -59,9 +60,7 @@ String synchronizeFile(String source) {
5960
parseFile(path: source, featureSet: FeatureSet.latestLanguageVersion())
6061
.unit
6162
.accept(visitor);
62-
return DartFormatter(
63-
languageVersion: Version.parse(Platform.version.split(' ').first))
64-
.format(visitor.result);
63+
return visitor.result;
6564
}
6665

6766
/// The visitor that traverses the asynchronous parse tree and converts it to

0 commit comments

Comments
 (0)