From a6f5873c4baa1443433b74e9a46d7818993907e2 Mon Sep 17 00:00:00 2001 From: oppahansi Date: Fri, 22 Dec 2023 16:05:43 +0100 Subject: [PATCH] chore: dropped all barrel files to not export any files. --- CHANGELOG.md | 4 ++ bin/better_imports.dart | 7 ++-- lib/{parser => }/arg_parser.dart | 2 +- lib/{config => }/cfg.dart | 5 ++- lib/cmds/cmds.dart | 1 - lib/collectors/collectors.dart | 1 - lib/config/config.dart | 1 - lib/{utils => }/constants.dart | 0 lib/extensions/extensions.dart | 1 - lib/{collectors => }/file_collector.dart | 7 +++- lib/{extensions => }/file_extension.dart | 0 lib/{sorters => }/import_sorter.dart | 7 ++-- lib/{utils => }/log.dart | 0 lib/parser/parser.dart | 1 - lib/{cmds => }/sort_cmd.dart | 10 ++--- lib/sorters/sorters.dart | 1 - lib/utils/utils.dart | 2 - pubspec.yaml | 2 +- test/cfg_test.dart | 6 +-- test/file_collector_test.dart | 47 ++++++------------------ test/sorter_test.dart | 8 ++-- 21 files changed, 45 insertions(+), 68 deletions(-) rename lib/{parser => }/arg_parser.dart (96%) rename lib/{config => }/cfg.dart (98%) delete mode 100644 lib/cmds/cmds.dart delete mode 100644 lib/collectors/collectors.dart delete mode 100644 lib/config/config.dart rename lib/{utils => }/constants.dart (100%) delete mode 100644 lib/extensions/extensions.dart rename lib/{collectors => }/file_collector.dart (96%) rename lib/{extensions => }/file_extension.dart (100%) rename lib/{sorters => }/import_sorter.dart (98%) rename lib/{utils => }/log.dart (100%) delete mode 100644 lib/parser/parser.dart rename lib/{cmds => }/sort_cmd.dart (86%) delete mode 100644 lib/sorters/sorters.dart delete mode 100644 lib/utils/utils.dart diff --git a/CHANGELOG.md b/CHANGELOG.md index dc665a3..39ead4e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## 1.0.1 +- Dropped all barrel files to not export anything. + +## 1.0.1 + - Updated readme with the Run on Save configuration option. ## 1.0.0 diff --git a/bin/better_imports.dart b/bin/better_imports.dart index 504f867..13320d2 100644 --- a/bin/better_imports.dart +++ b/bin/better_imports.dart @@ -7,9 +7,10 @@ import "package:intl/intl.dart"; import "package:logging/logging.dart"; // Project Imports -import "package:better_imports/cmds/cmds.dart"; -import "package:better_imports/parser/parser.dart"; -import "package:better_imports/utils/utils.dart"; +import "package:better_imports/arg_parser.dart"; +import "package:better_imports/constants.dart"; +import "package:better_imports/log.dart"; +import "package:better_imports/sort_cmd.dart"; void main(List args) { _setupLogging(); diff --git a/lib/parser/arg_parser.dart b/lib/arg_parser.dart similarity index 96% rename from lib/parser/arg_parser.dart rename to lib/arg_parser.dart index 736f6de..3cbc60d 100644 --- a/lib/parser/arg_parser.dart +++ b/lib/arg_parser.dart @@ -2,7 +2,7 @@ import 'package:args/args.dart'; // Project Imports -import 'package:better_imports/utils/utils.dart'; +import 'package:better_imports/constants.dart'; final argParser = ArgParser() ..addFlag( diff --git a/lib/config/cfg.dart b/lib/cfg.dart similarity index 98% rename from lib/config/cfg.dart rename to lib/cfg.dart index a460f3e..16800c8 100644 --- a/lib/config/cfg.dart +++ b/lib/cfg.dart @@ -6,8 +6,9 @@ import 'package:args/args.dart'; import 'package:yaml/yaml.dart'; // Project Imports -import 'package:better_imports/extensions/extensions.dart'; -import 'package:better_imports/utils/utils.dart'; +import 'package:better_imports/constants.dart'; +import 'package:better_imports/file_extension.dart'; +import 'package:better_imports/log.dart'; var logging = false; diff --git a/lib/cmds/cmds.dart b/lib/cmds/cmds.dart deleted file mode 100644 index d243edb..0000000 --- a/lib/cmds/cmds.dart +++ /dev/null @@ -1 +0,0 @@ -export 'sort_cmd.dart'; diff --git a/lib/collectors/collectors.dart b/lib/collectors/collectors.dart deleted file mode 100644 index 10897cc..0000000 --- a/lib/collectors/collectors.dart +++ /dev/null @@ -1 +0,0 @@ -export 'file_collector.dart'; diff --git a/lib/config/config.dart b/lib/config/config.dart deleted file mode 100644 index 860a21c..0000000 --- a/lib/config/config.dart +++ /dev/null @@ -1 +0,0 @@ -export 'cfg.dart'; diff --git a/lib/utils/constants.dart b/lib/constants.dart similarity index 100% rename from lib/utils/constants.dart rename to lib/constants.dart diff --git a/lib/extensions/extensions.dart b/lib/extensions/extensions.dart deleted file mode 100644 index 07a8438..0000000 --- a/lib/extensions/extensions.dart +++ /dev/null @@ -1 +0,0 @@ -export 'file_extension.dart'; diff --git a/lib/collectors/file_collector.dart b/lib/file_collector.dart similarity index 96% rename from lib/collectors/file_collector.dart rename to lib/file_collector.dart index e81361e..0c087b0 100644 --- a/lib/collectors/file_collector.dart +++ b/lib/file_collector.dart @@ -2,8 +2,8 @@ import 'dart:io'; // Project Imports -import 'package:better_imports/config/config.dart'; -import 'package:better_imports/utils/utils.dart'; +import 'package:better_imports/cfg.dart'; +import 'package:better_imports/log.dart'; class Collector { final Cfg cfg; @@ -49,6 +49,7 @@ class Collector { for (var pattern in cfg.ignoreFilesLike) { log.fine("┠─ Removing ignored file like: $pattern"); + _filteredFilePaths.removeWhere( (filePath) => RegExp(pattern).hasMatch(filePath), ); @@ -56,6 +57,7 @@ class Collector { for (var ignored in cfg.ignoreFiles) { log.fine("┠─ Removing ignored file: $ignored"); + _filteredFilePaths.removeWhere( (filePath) => filePath.endsWith("${Platform.pathSeparator}$ignored.dart"), @@ -77,6 +79,7 @@ class Collector { void _retainNamedFiles(List files) { log.fine("┠─ Retaining only named files.."); + _filteredFilePaths.retainWhere((element) { var fileName = element.split(Platform.pathSeparator).last; diff --git a/lib/extensions/file_extension.dart b/lib/file_extension.dart similarity index 100% rename from lib/extensions/file_extension.dart rename to lib/file_extension.dart diff --git a/lib/sorters/import_sorter.dart b/lib/import_sorter.dart similarity index 98% rename from lib/sorters/import_sorter.dart rename to lib/import_sorter.dart index 9bf74b9..96929bb 100644 --- a/lib/sorters/import_sorter.dart +++ b/lib/import_sorter.dart @@ -8,9 +8,10 @@ import 'package:analyzer/dart/ast/token.dart'; import 'package:dart_style/dart_style.dart'; // Project Imports -import 'package:better_imports/collectors/collectors.dart'; -import 'package:better_imports/config/config.dart'; -import 'package:better_imports/utils/utils.dart'; +import 'package:better_imports/cfg.dart'; +import 'package:better_imports/constants.dart'; +import 'package:better_imports/file_collector.dart'; +import 'package:better_imports/log.dart'; enum ImportType { dart, diff --git a/lib/utils/log.dart b/lib/log.dart similarity index 100% rename from lib/utils/log.dart rename to lib/log.dart diff --git a/lib/parser/parser.dart b/lib/parser/parser.dart deleted file mode 100644 index a95e63f..0000000 --- a/lib/parser/parser.dart +++ /dev/null @@ -1 +0,0 @@ -export 'arg_parser.dart'; diff --git a/lib/cmds/sort_cmd.dart b/lib/sort_cmd.dart similarity index 86% rename from lib/cmds/sort_cmd.dart rename to lib/sort_cmd.dart index a566bdc..8d682d6 100644 --- a/lib/cmds/sort_cmd.dart +++ b/lib/sort_cmd.dart @@ -3,11 +3,11 @@ import 'package:args/args.dart'; import 'package:tint/tint.dart'; // Project Imports -import 'package:better_imports/collectors/collectors.dart'; -import 'package:better_imports/config/config.dart'; -import 'package:better_imports/extensions/extensions.dart'; -import 'package:better_imports/sorters/sorters.dart'; -import 'package:better_imports/utils/utils.dart'; +import 'package:better_imports/cfg.dart'; +import 'package:better_imports/file_collector.dart'; +import 'package:better_imports/file_extension.dart'; +import 'package:better_imports/import_sorter.dart'; +import 'package:better_imports/log.dart'; class SortCmd { final ArgResults argResults; diff --git a/lib/sorters/sorters.dart b/lib/sorters/sorters.dart deleted file mode 100644 index 0442042..0000000 --- a/lib/sorters/sorters.dart +++ /dev/null @@ -1 +0,0 @@ -export 'import_sorter.dart'; diff --git a/lib/utils/utils.dart b/lib/utils/utils.dart deleted file mode 100644 index 18426ef..0000000 --- a/lib/utils/utils.dart +++ /dev/null @@ -1,2 +0,0 @@ -export 'constants.dart'; -export 'log.dart'; diff --git a/pubspec.yaml b/pubspec.yaml index ec5c558..929c331 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: better_imports description: A better imports sorter for your .dart files. -version: 1.0.1 +version: 1.0.2 repository: https://github.com/oppahansi/better_imports executables: diff --git a/test/cfg_test.dart b/test/cfg_test.dart index b47b636..3afd25d 100644 --- a/test/cfg_test.dart +++ b/test/cfg_test.dart @@ -5,9 +5,9 @@ import 'dart:io'; import 'package:test/test.dart'; // Project Imports -import 'package:better_imports/config/config.dart'; -import 'package:better_imports/extensions/extensions.dart'; -import 'package:better_imports/parser/parser.dart'; +import 'package:better_imports/arg_parser.dart'; +import 'package:better_imports/cfg.dart'; +import 'package:better_imports/file_extension.dart'; void main() { group("Cfg Tests.", () { diff --git a/test/file_collector_test.dart b/test/file_collector_test.dart index 1aa807a..da881ef 100644 --- a/test/file_collector_test.dart +++ b/test/file_collector_test.dart @@ -2,9 +2,9 @@ import 'package:test/test.dart'; // Project Imports -import 'package:better_imports/collectors/collectors.dart'; -import 'package:better_imports/config/config.dart'; -import 'package:better_imports/parser/parser.dart'; +import 'package:better_imports/arg_parser.dart'; +import 'package:better_imports/cfg.dart'; +import 'package:better_imports/file_collector.dart'; void main() { group("Collector Tests. Test amount of collected files.", () { @@ -26,7 +26,7 @@ void main() { var collector = Collector(cfg: cfg); var collectorResult = collector.collect(); - expect(collectorResult.filteredPaths.length, 3); + expect(collectorResult.filteredPaths.length, 2); }); test("files-like arg provided", () { @@ -41,7 +41,7 @@ void main() { }); test("folders arg provided", () { - var args = ["--folders", "lib/cmds, lib/collectors, lib/utils"]; + var args = ["--folders", "lib"]; var argResult = argParser.parse(args); var cfg = Cfg(argResult); @@ -52,22 +52,14 @@ void main() { }); test("ignore-files arg provided, ignore some dart files", () { - var args = []; + var args = ["--ignore-files", "sort_cmd"]; var argResult = argParser.parse(args); var cfg = Cfg(argResult); var collector = Collector(cfg: cfg); - var collectorResult = collector.collect(); - - args = ["--ignore-files", "parser"]; - argResult = argParser.parse(args); - cfg = Cfg(argResult); - - collector = Collector(cfg: cfg); var collected = collector.collect(); - expect( - collected.filteredPaths.length, collectorResult.allPaths.length - 1); + expect(collected.filteredPaths.length, collected.allPaths.length - 1); }); test("ignore-files-like arg provided, ignore all dart files", () { @@ -82,42 +74,25 @@ void main() { }); test("ignore-files-like arg provided, ignore only given files", () { - var args = []; + var args = ["--ignore-files-like", r".*sort_cmd\.dart"]; var argResult = argParser.parse(args); var cfg = Cfg(argResult); var collector = Collector(cfg: cfg); - var collectorResult = collector.collect(); - - args = ["--ignore-files-like", r".*sort_cmd\.dart"]; - argResult = argParser.parse(args); - cfg = Cfg(argResult); - - collector = Collector(cfg: cfg); var collected = collector.collect(); - expect(collected.filteredPaths.length, - collectorResult.filteredPaths.length - 1); + expect(collected.filteredPaths.length, collected.allPaths.length - 1); }); test("recursive arg provided, recursive false", () { - var args = []; + var args = ["--no-recursive"]; var argResult = argParser.parse(args); var cfg = Cfg(argResult); var collector = Collector(cfg: cfg); - var collectorResult = collector.collect(); - - args = ["--no-recursive"]; - argResult = argParser.parse(args); - cfg = Cfg(argResult); - - collector = Collector(cfg: cfg); var collected = collector.collect(); - expect( - collected.filteredPaths.length < collectorResult.filteredPaths.length, - true); + expect(collected.filteredPaths.length == collected.allPaths.length, true); }); }); } diff --git a/test/sorter_test.dart b/test/sorter_test.dart index 05e67a8..762a0b4 100644 --- a/test/sorter_test.dart +++ b/test/sorter_test.dart @@ -6,10 +6,10 @@ import 'package:dart_style/dart_style.dart'; import 'package:test/test.dart'; // Project Imports -import 'package:better_imports/collectors/collectors.dart'; -import 'package:better_imports/config/config.dart'; -import 'package:better_imports/parser/parser.dart'; -import 'package:better_imports/sorters/sorters.dart'; +import 'package:better_imports/arg_parser.dart'; +import 'package:better_imports/cfg.dart'; +import 'package:better_imports/file_collector.dart'; +import 'package:better_imports/import_sorter.dart'; // Relative Project Imports import '../res/sorter_fixtures.dart';