|
2 | 2 | // for details. All rights reserved. Use of this source code is governed by a |
3 | 3 | // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
|
5 | | -import 'dart:io'; |
| 5 | +// import 'dart:io'; |
6 | 6 |
|
7 | 7 | import 'package:test/test.dart'; |
8 | 8 |
|
9 | | -final _whitespace = RegExp(r'\s+'); |
| 9 | +// final _whitespace = RegExp(r'\s+'); |
10 | 10 |
|
11 | | -const _colors = { |
12 | | - 'black', |
13 | | - 'red', |
14 | | - 'white', |
15 | | -}; |
| 11 | +// const _colors = { |
| 12 | +// 'black', |
| 13 | +// 'red', |
| 14 | +// 'white', |
| 15 | +// }; |
16 | 16 |
|
17 | 17 | void main() { |
18 | 18 | group('Color restrictions and rules', () { |
19 | | - test('text and bg colors are only defined in _variables.scss', |
20 | | - skip: 'https://github.com/dart-lang/pub-dev/issues/8248', () { |
21 | | - final files = Directory('lib') |
22 | | - .listSync(recursive: true) |
23 | | - .whereType<File>() |
24 | | - .where((f) => f.path.endsWith('.scss')) |
25 | | - // _variables.scss is not checked, this should be the place for all color definitions |
26 | | - .where((f) => !f.path.endsWith('/_variables.scss')) |
27 | | - |
28 | | - // _staging_ribbon.scss is only used on staging |
29 | | - .where((f) => !f.path.endsWith('/_staging_ribbon.scss')) |
30 | | - |
31 | | - // _footer.scss has only one color theme, skipping for now |
32 | | - // TODO: migrate the variables in this file |
33 | | - .where((f) => !f.path.endsWith('/_footer.scss')) |
34 | | - |
35 | | - // dartdoc files are not checked |
36 | | - .where((f) => !f.path.endsWith('/dartdoc.scss')) |
37 | | - .toList(); |
38 | | - |
39 | | - final badExpressions = <String>[]; |
40 | | - |
41 | | - for (final file in files) { |
42 | | - var content = file.readAsStringSync(); |
43 | | - // remove multi-line comment blocks |
44 | | - content = |
45 | | - content.replaceAll(RegExp(r'\/\*.*\*/', multiLine: true), ' '); |
46 | | - final lines = content.split('\n'); |
47 | | - for (var i = 0; i < lines.length; i++) { |
48 | | - final line = lines[i]; |
49 | | - // remove single-line comment |
50 | | - final expr = |
51 | | - line.split('//').first.replaceAll(_whitespace, ' ').trim(); |
52 | | - if (expr.isEmpty) continue; |
53 | | - |
54 | | - // minimal parsing and sanity check |
55 | | - final parts = expr.split(':'); |
56 | | - if (parts.length != 2) continue; |
57 | | - final name = parts[0].trim(); |
58 | | - var value = parts[1].trim(); |
59 | | - |
60 | | - // remove known overlapping variable names from checking |
61 | | - value = |
62 | | - value.replaceAll('--pub-badge-red-color', '--pub-badge-color'); |
63 | | - |
64 | | - if (name.isEmpty || value.isEmpty) continue; |
65 | | - |
66 | | - // local mdc overrides are exempted for now |
67 | | - // TODO: move these values to _variables.scss |
68 | | - if (name.startsWith('--mdc-theme-')) { |
69 | | - continue; |
70 | | - } |
71 | | - |
72 | | - // border colors, box shadows and text-decorations are exempted for now |
73 | | - // TODO: move these values to _variables.scss |
74 | | - if (name == 'border' || |
75 | | - name.startsWith('border-') || |
76 | | - name == 'box-shadow' || |
77 | | - name == 'text-decoration') { |
78 | | - continue; |
79 | | - } |
80 | | - |
81 | | - // detect color patterns |
82 | | - final hasColor = value.contains('#') || |
83 | | - // TODO: also migrate color- variables |
84 | | - // value.contains(r'$color-') || |
85 | | - value.contains('rgb(') || |
86 | | - value.contains('rgba(') || |
87 | | - value.contains('hsl(') || |
88 | | - _colors.any((c) => value.contains(c)); |
89 | | - if (!hasColor) continue; |
90 | | - |
91 | | - badExpressions.add('${file.path} line #${i + 1}: `${expr.trim()}`'); |
92 | | - } |
93 | | - } |
94 | | - |
95 | | - expect(badExpressions, isEmpty); |
96 | | - }); |
| 19 | + // TODO(https://github.com/dart-lang/pub-dev/issues/8248): comment in once issue is resolved. |
| 20 | + // test('text and bg colors are only defined in _variables.scss', |
| 21 | + // skip: 'https://github.com/dart-lang/pub-dev/issues/8248', () { |
| 22 | + // final files = Directory('lib') |
| 23 | + // .listSync(recursive: true) |
| 24 | + // .whereType<File>() |
| 25 | + // .where((f) => f.path.endsWith('.scss')) |
| 26 | + // // _variables.scss is not checked, this should be the place for all color definitions |
| 27 | + // .where((f) => !f.path.endsWith('/_variables.scss')) |
| 28 | + |
| 29 | + // // _staging_ribbon.scss is only used on staging |
| 30 | + // .where((f) => !f.path.endsWith('/_staging_ribbon.scss')) |
| 31 | + |
| 32 | + // // _footer.scss has only one color theme, skipping for now |
| 33 | + // // TODO: migrate the variables in this file |
| 34 | + // .where((f) => !f.path.endsWith('/_footer.scss')) |
| 35 | + |
| 36 | + // // dartdoc files are not checked |
| 37 | + // .where((f) => !f.path.endsWith('/dartdoc.scss')) |
| 38 | + // .toList(); |
| 39 | + |
| 40 | + // final badExpressions = <String>[]; |
| 41 | + |
| 42 | + // for (final file in files) { |
| 43 | + // var content = file.readAsStringSync(); |
| 44 | + // // remove multi-line comment blocks |
| 45 | + // content = |
| 46 | + // content.replaceAll(RegExp(r'\/\*.*\*/', multiLine: true), ' '); |
| 47 | + // final lines = content.split('\n'); |
| 48 | + // for (var i = 0; i < lines.length; i++) { |
| 49 | + // final line = lines[i]; |
| 50 | + // // remove single-line comment |
| 51 | + // final expr = |
| 52 | + // line.split('//').first.replaceAll(_whitespace, ' ').trim(); |
| 53 | + // if (expr.isEmpty) continue; |
| 54 | + |
| 55 | + // // minimal parsing and sanity check |
| 56 | + // final parts = expr.split(':'); |
| 57 | + // if (parts.length != 2) continue; |
| 58 | + // final name = parts[0].trim(); |
| 59 | + // var value = parts[1].trim(); |
| 60 | + |
| 61 | + // // remove known overlapping variable names from checking |
| 62 | + // value = |
| 63 | + // value.replaceAll('--pub-badge-red-color', '--pub-badge-color'); |
| 64 | + |
| 65 | + // if (name.isEmpty || value.isEmpty) continue; |
| 66 | + |
| 67 | + // // local mdc overrides are exempted for now |
| 68 | + // // TODO: move these values to _variables.scss |
| 69 | + // if (name.startsWith('--mdc-theme-')) { |
| 70 | + // continue; |
| 71 | + // } |
| 72 | + |
| 73 | + // // border colors, box shadows and text-decorations are exempted for now |
| 74 | + // // TODO: move these values to _variables.scss |
| 75 | + // if (name == 'border' || |
| 76 | + // name.startsWith('border-') || |
| 77 | + // name == 'box-shadow' || |
| 78 | + // name == 'text-decoration') { |
| 79 | + // continue; |
| 80 | + // } |
| 81 | + |
| 82 | + // // detect color patterns |
| 83 | + // final hasColor = value.contains('#') || |
| 84 | + // // TODO: also migrate color- variables |
| 85 | + // // value.contains(r'$color-') || |
| 86 | + // value.contains('rgb(') || |
| 87 | + // value.contains('rgba(') || |
| 88 | + // value.contains('hsl(') || |
| 89 | + // _colors.any((c) => value.contains(c)); |
| 90 | + // if (!hasColor) continue; |
| 91 | + |
| 92 | + // badExpressions.add('${file.path} line #${i + 1}: `${expr.trim()}`'); |
| 93 | + // } |
| 94 | + // } |
| 95 | + |
| 96 | + // expect(badExpressions, isEmpty); |
| 97 | + // }); |
97 | 98 | }); |
98 | 99 | } |
0 commit comments