Skip to content
This repository has been archived by the owner on Jul 16, 2023. It is now read-only.

Commit

Permalink
Merge c52fa1c into 4b3ebb9
Browse files Browse the repository at this point in the history
  • Loading branch information
zmeggyesi authored Dec 27, 2020
2 parents 4b3ebb9 + c52fa1c commit cbc8dc8
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/src/ignore_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@ class IgnoreInfo {
bool get hasIgnoreInfo =>
_ignoreMap.isNotEmpty || _ignoreForFileSet.isNotEmpty;

bool ignoreRule(String ruleId) => _ignoreForFileSet.contains(ruleId);
bool ignoreRule(String ruleId) =>
_ignoreForFileSet.contains(canonicalize(ruleId));

bool ignoredAt(String ruleId, int line) =>
ignoreRule(ruleId) || (_ignoreMap[line]?.contains(ruleId) ?? false);
ignoreRule(canonicalize(ruleId)) ||
(_ignoreMap[line]?.contains(canonicalize(ruleId)) ?? false);

String canonicalize(String ruleId) => ruleId.trim().toLowerCase();

IgnoreInfo.calculateIgnores(String content, LineInfo info) {
for (final match in _ignoreMatchers.allMatches(content)) {
final codes =
match.group(1).split(',').map((code) => code.trim().toLowerCase());
final codes = match.group(1).split(',').map(canonicalize);
final location = info.getLocation(match.start);
final lineNumber = location.lineNumber;
final beforeMatch = content.substring(
Expand All @@ -37,8 +40,7 @@ class IgnoreInfo {
}

for (final match in _ignoreForFileMatcher.allMatches(content)) {
_ignoreForFileSet.addAll(
match.group(1).split(',').map((code) => code.trim().toLowerCase()));
_ignoreForFileSet.addAll(match.group(1).split(',').map(canonicalize));
}
}
}
42 changes: 42 additions & 0 deletions test/ignore_info_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ void main() {
// ignore_for_file: rule_id2, rule_id3
''';

const _contentWithCamelCaseIgnores = '''
// ignore_for_file: ruleId1
void main() {
// ignore: ruleId4
var a = 5; // ignore: ruleId5
// ignore: ruleId6, ruleId7
var b = a + 5; // ignore: ruleId8, ruleId9
}
// ignore_for_file: ruleId2, ruleId3
''';

void main() {
group('IgnoreInfo from', () {
test('content without ignores', () {
Expand Down Expand Up @@ -70,5 +84,33 @@ void main() {
expect(ignoreInfo.ignoredAt('rule_id8', 8), isTrue);
expect(ignoreInfo.ignoredAt('rule_id9', 8), isTrue);
});

test('content with camelcase ignores', () {
final parseResult = parseString(
content: _contentWithCamelCaseIgnores,
featureSet: FeatureSet.fromEnableFlags([]),
throwIfDiagnostics: false,
);

final ignoreInfo = IgnoreInfo.calculateIgnores(
parseResult.content, parseResult.lineInfo);

expect(ignoreInfo.hasIgnoreInfo, isTrue);

expect(ignoreInfo.ignoreRule('ruleId1'), isTrue);
expect(ignoreInfo.ignoreRule('ruleId2'), isTrue);
expect(ignoreInfo.ignoreRule('ruleId3'), isTrue);
expect(ignoreInfo.ignoreRule('ruleId4'), isFalse);

expect(ignoreInfo.ignoredAt('ruleId1', 5), isTrue);
expect(ignoreInfo.ignoredAt('ruleId2', 8), isTrue);
expect(ignoreInfo.ignoredAt('ruleId3', 2), isTrue);
expect(ignoreInfo.ignoredAt('ruleId4', 5), isTrue);
expect(ignoreInfo.ignoredAt('ruleId5', 5), isTrue);
expect(ignoreInfo.ignoredAt('ruleId6', 8), isTrue);
expect(ignoreInfo.ignoredAt('ruleId7', 8), isTrue);
expect(ignoreInfo.ignoredAt('ruleId8', 8), isTrue);
expect(ignoreInfo.ignoredAt('ruleId9', 8), isTrue);
});
});
}

0 comments on commit cbc8dc8

Please sign in to comment.