Skip to content

Commit

Permalink
Formatted files in accordance with dartfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
vxern committed Aug 22, 2021
1 parent 7f396e3 commit 6796218
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 148 deletions.
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# Files and directories created by pub.
.dart_tool/
.packages

# Conventional directory for build output.
build/
pubspec.lock
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@

- Fixed the reading of the contents of `robots.txt`
- Fixed the parsing of rule fields to `Rule`s
- Added `example.dart`
- Added `example.dart`

## 1.1.0+1

- Formatted files in accordance with `dartfmt`
4 changes: 2 additions & 2 deletions example/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Future main() async {
await robots.read();
// Print the ruleset
for (final ruleset in robots.rulesets) {
// Print the user-agent the ruleset applies to
// Print the user-agent the ruleset applies to
print(ruleset.appliesTo);
if (ruleset.allows.isNotEmpty) {
print('Allows:');
Expand All @@ -29,4 +29,4 @@ Future main() async {
// True, it can
print(robots.canVisitPath('/wordcollector/robots_txt', userAgent: '*'));
return;
}
}
13 changes: 5 additions & 8 deletions lib/src/parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'package:web_scraper/web_scraper.dart';

import 'package:robots_txt/src/rule.dart';
import 'package:robots_txt/src/ruleset.dart';
import 'package:robots_txt/src/utils.dart';

/// Abstracts away the rather convoluted declaration for an element with two
/// fields; 'title' and 'attributes'. 'attributes' is a map containing the
Expand Down Expand Up @@ -95,19 +94,17 @@ class Robots {
/// regular expression for later matching
RegExp convertFieldPathToExpression(String pathDeclaration) {
// Collapse duplicate slashes and wildcards into singles
final collapsed = pathDeclaration
.replaceAll('/+', '/')
.replaceAll('*+', '*');
final collapsed =
pathDeclaration.replaceAll('/+', '/').replaceAll('*+', '*');
final normalised = collapsed.endsWith('*')
? collapsed.substring(0, collapsed.length - 1)
: collapsed;
final withWildcardsReplaced = normalised
.replaceAll('.', r'\.')
.replaceAll('*', '.*');
final withWildcardsReplaced =
normalised.replaceAll('.', r'\.').replaceAll('*', '.*');
final withTrailingText = withWildcardsReplaced.contains(r'$')
? withWildcardsReplaced.split(r'$')[0]
: '$withWildcardsReplaced.*';
return RegExp(withTrailingText, caseSensitive: false, dotAll: true);
return RegExp(withTrailingText, caseSensitive: false, dotAll: true);
}

/// Extracts the key and value from [target] and puts it into a `MapEntry`
Expand Down
4 changes: 2 additions & 2 deletions lib/src/utils.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/// Taking the singular form of [word], morph it according to [count]
String pluralise(String word, int count) =>
'${count == 0 ? 'no' : count} ${count == 0 || count > 1 ? '${word}s' : word}';
String pluralise(String word, int count) => '${count == 0 ? 'no' : count} '
'${count == 0 || count > 1 ? '${word}s' : word}';
131 changes: 0 additions & 131 deletions pubspec.lock

This file was deleted.

2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
publish_to: https://pub.dev

name: robots_txt
version: 1.1.0
version: 1.1.0+1

description: Lightweight, sturdy and fully-documented parser of the `robots.txt` file.

Expand Down

0 comments on commit 6796218

Please sign in to comment.