Skip to content

Commit

Permalink
Typos, naming
Browse files Browse the repository at this point in the history
  • Loading branch information
solid-yuriiprykhodko committed Sep 22, 2023
1 parent 103d8dc commit fc23c9c
Showing 1 changed file with 30 additions and 23 deletions.
53 changes: 30 additions & 23 deletions lib/lints/prefer_match_file_name/prefer_match_file_name_rule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,33 +42,40 @@ class PreferMatchFileNameRule extends SolidLintRule {

if (visitor.declarations.isEmpty) return;

final info = visitor.declarations.first;
if (!_hasMatchName(resolver.source.fullName, info.token.lexeme)) {
final nodeType = humanReadableNodeType(info.parent).toLowerCase();
final firstDeclaration = visitor.declarations.first;

reporter.reportErrorForToken(
LintCode(
name: lintName,
problemMessage:
'File name does not match with first $nodeType name.',
),
info.token,
);
}
if (_doNormalizedNamesMatch(
resolver.source.fullName,
firstDeclaration.token.lexeme,
)) return;

final nodeType =
humanReadableNodeType(firstDeclaration.parent).toLowerCase();

reporter.reportErrorForToken(
LintCode(
name: lintName,
problemMessage: 'File name does not match with first $nodeType name.',
),
firstDeclaration.token,
);
});
}

bool _hasMatchName(String path, String identifierName) {
final identifierNameFormatted =
identifierName.replaceAll(_onlySymbolsRegex, '').toLowerCase();

final fileNameFormatted = p
.basename(path)
.split('.')
.first
.replaceAll(_onlySymbolsRegex, '')
.toLowerCase();
bool _doNormalizedNamesMatch(String path, String identifierName) {
final fileName = _normalizePath(path);
final dartIdentifier = _normalizeDartIdentifierName(identifierName);

return identifierNameFormatted == fileNameFormatted;
return fileName == dartIdentifier;
}

String _normalizePath(String s) => p
.basename(s)
.split('.')
.first
.replaceAll(_onlySymbolsRegex, '')
.toLowerCase();

String _normalizeDartIdentifierName(String s) =>
s.replaceAll(_onlySymbolsRegex, '').toLowerCase();
}

0 comments on commit fc23c9c

Please sign in to comment.