diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 30f0ce2..00087cd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,13 +4,10 @@ jobs: build: runs-on: ubuntu-latest steps: - - - name: 'Checkout code' - uses: actions/checkout@v3 - - - name: 'Tests' - uses: subosito/flutter-action@v2 + - uses: actions/checkout@v3 + - uses: subosito/flutter-action@v2 with: flutter-version: '3.x' channel: 'stable' - - run: make + - run: make install + - run: make check diff --git a/Makefile b/Makefile index f7ac3a6..5a3983e 100644 --- a/Makefile +++ b/Makefile @@ -1,43 +1,7 @@ -default: check +include weather_app/Tasks.mk -.PHONY: tasks -tasks: ## Print available tasks - @printf "\nUsage: make [target]\n\n" - @grep -E '^[a-z][^:]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' +.PHONY: install check -.PHONY: cyclic_dependency_checks/install -cyclic_dependency_checks/install: ## Fetch dependencies for cyclic_dependency_checks - cd cyclic_dependency_checks; dart pub get +install: weather_app/install -.PHONY: cyclic_dependency_checks/format -cyclic_dependency_checks/format: ## Format cyclic_dependency_checks code - cd cyclic_dependency_checks; dart format lib --line-length 100 --set-exit-if-changed - -.PHONY: cyclic_dependency_checks/test -cyclic_dependency_checks/test: ## Run cyclic_dependency_checks tests - cd cyclic_dependency_checks; dart scripts/generate_big_codebase.dart && dart test - -.PHONY: weather_app/install -weather_app/install: ## Fetch dependencies for weather_app - cd weather_app; flutter pub get - -.PHONY: weather_app/format -weather_app/format: ## Format weather_app code - cd weather_app; dart format lib --line-length 100 --set-exit-if-changed - -.PHONY: weather_app/test -weather_app/test: ## Run weather_app tests - cd weather_app; flutter test - -.PHONY: format -format: cyclic_dependency_checks/format weather_app/format ## Format all code - -.PHONY: test -test: cyclic_dependency_checks/test weather_app/test ## Run all tests - -.PHONY: check-cycles -check-cycles: ## Test cyclic dependencies - cd cyclic_dependency_checks; dart run cyclic_dependency_checks ../weather_app - -.PHONY: check -check: format test check-cycles ## Check formatting and run tests +check: weather_app/check diff --git a/README.md b/README.md index 30c36ec..84cf6ed 100644 --- a/README.md +++ b/README.md @@ -50,44 +50,23 @@ dependency injection and predictable testing of API integrations. * Select in Android Studio's device list * Run `main.dart` -## Running tests +## Running checks + +This checks formatting, runs tests and checks for dependency cycles ``` -make test +make check ``` -## Formatting +### Formatting We use a line length of `100` characters, which is good enough to show two files side by side on a modern 27 inch screen. Line length can be set in Android Studio `Preferences > Editor > Code Style > Dart`. -``` -make format -``` - -If your prefer a different line length, feel free to update the `Makefile` to your team's liking +If your prefer a different line length, feel free to update the `Tasks.mk` to your team's liking and have developers configure their IDE as well. -## Checking for cyclic dependencies +### Cyclic dependencies Make sure your imports are relative only for files in the same folder, otherwise use `package:` imports. -Run the make task for checking cycles: - -``` -make check-cycles -``` - -## Check before push - -To check formatting, cyclic dependencies and run tests before pushing your code - -``` -make check -``` - -or - -``` -make -``` diff --git a/cyclic_dependency_checks/bin/cyclic_dependency_checks.dart b/cyclic_dependency_checks/bin/cyclic_dependency_checks.dart deleted file mode 100644 index 5717dd3..0000000 --- a/cyclic_dependency_checks/bin/cyclic_dependency_checks.dart +++ /dev/null @@ -1,41 +0,0 @@ -import 'dart:io'; - -import 'package:cyclic_dependency_checks/cycle_detection/cycle_detector.dart'; -import 'package:cyclic_dependency_checks/cycle_detection/module_dependency.dart'; -import 'package:cyclic_dependency_checks/cycle_detection/module_dependency_graph.dart'; - -void main(List args) async { - switch (args) { - case [final path]: - await _run(path); - default: - throw Exception( - 'Expected exactly only one argument, ' - 'the path to dart package folder as argument', - ); - } -} - -Future _run(String path) async { - final stopwatch = Stopwatch()..start(); - final cycles = await CycleDetector().detect(path); - stopwatch.stop(); - - final formattedTime = stopwatch.elapsed.toString().substring(0, 11); - - if (cycles.isNotEmpty) { - stderr.writeln('Detected cycles after ${formattedTime}'); - for (var cycle in cycles) { - cycle.printError(); - } - exit(1); - } - - stdout.writeln('No import cycles were detected after ${formattedTime}'); -} - -extension ErrorPrinting on List { - void printError() { - stderr.writeln(path().join(' -> ')); - } -} diff --git a/cyclic_dependency_checks/lib/cycle_detection/cycle_detector.dart b/cyclic_dependency_checks/lib/cycle_detection/cycle_detector.dart deleted file mode 100644 index 89777e9..0000000 --- a/cyclic_dependency_checks/lib/cycle_detection/cycle_detector.dart +++ /dev/null @@ -1,80 +0,0 @@ -import 'dart:io'; - -import 'imported_dependency.dart'; -import 'module_dependency.dart'; -import 'module_dependency_graph.dart'; - -class CycleDetector { - Future>> detect( - String packagePath, { - int? maxDepth, - }) async { - final pubspecFile = File('$packagePath/pubspec.yaml'); - final pubspecContent = await pubspecFile.readAsLines(); - final appPackage = pubspecContent.firstOrNull?.replaceFirst('name: ', ''); - final libPath = '$packagePath/lib'; - - if (appPackage == null) { - throw Exception( - 'Could not read appPackage from file ${pubspecFile.absolute.path}', - ); - } - - final graph = await _loadDependencyGraph(appPackage, libPath); - - return graph.detectCycles(maxDepth: maxDepth); - } - - Future _loadDependencyGraph( - String appPackage, - String libPath, - ) async { - final graph = ModuleDependencyGraph(appPackage: appPackage); - - await for (final entity in Directory(libPath).list(recursive: true)) { - List validImports = - await _findValidImportsInFile(entity, libPath, appPackage); - - graph.addAll(validImports); - } - - return graph; - } - - Future> _findValidImportsInFile( - FileSystemEntity fileSystemEntity, - String libPath, - String appPackage, - ) async { - final entityPath = fileSystemEntity.path; - - if (!entityPath.endsWith('.dart')) { - return []; - } - - final content = await File(entityPath).readAsString(); - final relativePath = entityPath.replaceFirst(libPath, ''); - final source = SourceFile(relativePath); - - final importResults = content - .split('\n') - .where((line) => line.startsWith('import ')) - .map((line) => ImportedDependency.tryCreate(appPackage, source, line)); - - for (var res in importResults) { - if (res is DisallowedNestedImport) { - throw Exception( - 'Found a disallowed dependency, from $entityPath to ${res.import}', - ); - } - } - - final validImports = importResults - .expand( - (result) => result is ValidImport ? [result.dependency] : [], - ) - .toList(); - - return validImports; - } -} diff --git a/cyclic_dependency_checks/lib/cycle_detection/imported_dependency.dart b/cyclic_dependency_checks/lib/cycle_detection/imported_dependency.dart deleted file mode 100644 index 160eb52..0000000 --- a/cyclic_dependency_checks/lib/cycle_detection/imported_dependency.dart +++ /dev/null @@ -1,123 +0,0 @@ -import 'module_dependency.dart'; - -class ImportedDependency { - final String appPackage; - final SourceFile source; - final String import; - final Module sourceModule; - final Module importedModule; - - ImportedDependency._( - this.appPackage, - this.source, - this.import, - this.sourceModule, - this.importedModule, - ); - - @override - String toString() => 'src: ${source.path}, import: $import'; - - static DependencyCreationResult tryCreate( - String appPackage, - SourceFile source, - String importLine, - ) { - final import = importLine.split("'")[1]; - final isStandardLibrary = import.startsWith('dart:'); - final isPackageDependency = import.startsWith('package:'); - final isAppPackageDependency = import.startsWith('package:$appPackage'); - - if (isStandardLibrary) { - return IgnoredStandardLibrary(import); - } - - if (isPackageDependency && !isAppPackageDependency) { - return IgnoredExternalPackage(import); - } - - final isRelative = !isAppPackageDependency; - final isNested = import.contains('/'); - - if (isRelative && isNested) { - return DisallowedNestedImport(import); - } - - if (isRelative) { - return IgnoredInnerImport(import); - } - - final sourceModule = _sourceModule(appPackage, source); - final importedModule = _importedModule(appPackage, import, sourceModule); - - if (importedModule == sourceModule) { - return IgnoredInnerImport(import); - } - - return ValidImport(ImportedDependency._( - appPackage, - source, - import, - sourceModule, - importedModule, - )); - } - - static Module _sourceModule(String appPackage, SourceFile source) { - final components = source.path.split('/') - ..removeLast() - ..removeAt(0) - ..insert(0, appPackage); - final path = components.join('/'); - - return Module(path); - } - - static Module _importedModule( - String appPackage, - String import, - Module sourceModule, - ) { - final components = import.replaceFirst('package:', '').split('/')..removeLast(); - - return Module(components.join('/')); - } -} - -class SourceFile { - final String path; - - SourceFile(this.path); -} - -sealed class DependencyCreationResult {} - -class ValidImport implements DependencyCreationResult { - final ImportedDependency dependency; - - ValidImport(this.dependency); -} - -class IgnoredStandardLibrary implements DependencyCreationResult { - final String import; - - IgnoredStandardLibrary(this.import); -} - -class IgnoredExternalPackage implements DependencyCreationResult { - final String import; - - IgnoredExternalPackage(this.import); -} - -class DisallowedNestedImport implements DependencyCreationResult { - final String import; - - DisallowedNestedImport(this.import); -} - -class IgnoredInnerImport implements DependencyCreationResult { - final String import; - - IgnoredInnerImport(this.import); -} diff --git a/cyclic_dependency_checks/lib/cycle_detection/list_extensions.dart b/cyclic_dependency_checks/lib/cycle_detection/list_extensions.dart deleted file mode 100644 index d50c83f..0000000 --- a/cyclic_dependency_checks/lib/cycle_detection/list_extensions.dart +++ /dev/null @@ -1,11 +0,0 @@ -extension Flatten on List> { - List flatten() { - final result = []; - - for (final list in this) { - result.addAll(list); - } - - return result; - } -} diff --git a/cyclic_dependency_checks/lib/cycle_detection/module_dependency.dart b/cyclic_dependency_checks/lib/cycle_detection/module_dependency.dart deleted file mode 100644 index b14aad9..0000000 --- a/cyclic_dependency_checks/lib/cycle_detection/module_dependency.dart +++ /dev/null @@ -1,37 +0,0 @@ -class Module { - final String path; - - Module(this.path); - - @override - bool operator ==(Object other) => - identical(this, other) || - other is Module && runtimeType == other.runtimeType && path == other.path; - - @override - int get hashCode => path.hashCode; - - @override - String toString() => 'module:$path'; -} - -class ModuleDependency { - final Module from; - final Module to; - - ModuleDependency({required this.from, required this.to}); - - @override - bool operator ==(Object other) => - identical(this, other) || - other is ModuleDependency && - runtimeType == other.runtimeType && - from == other.from && - to == other.to; - - @override - int get hashCode => from.hashCode ^ to.hashCode; - - @override - String toString() => '$from -> $to'; -} diff --git a/cyclic_dependency_checks/lib/cycle_detection/module_dependency_graph.dart b/cyclic_dependency_checks/lib/cycle_detection/module_dependency_graph.dart deleted file mode 100644 index d54086a..0000000 --- a/cyclic_dependency_checks/lib/cycle_detection/module_dependency_graph.dart +++ /dev/null @@ -1,80 +0,0 @@ -import 'dart:isolate'; - -import 'imported_dependency.dart'; -import 'list_extensions.dart'; -import 'module_dependency.dart'; - -class ModuleDependencyGraph { - final String appPackage; - final List _dependencies = []; - final Set _moduleDependencies = {}; - - ModuleDependencyGraph({required this.appPackage}); - - void addAll(List dependencies) { - _dependencies.addAll(dependencies); - _moduleDependencies.addAll(dependencies.map( - (d) => ModuleDependency(from: d.sourceModule, to: d.importedModule), - )); - } - - Future>> detectCycles({int? maxDepth}) async { - final moduleCount = _countModules(); - final actualMaxDepth = maxDepth ?? moduleCount; - - final resultsFutures = _moduleDependencies.map( - (value) => Isolate.run( - () => _detectDependencyCycles([value], maxDepth: actualMaxDepth), - ), - ); - - return (await Future.wait(resultsFutures)).flatten(); - } - - int _countModules() { - final allModules = {}; - - for (var value in _moduleDependencies) { - allModules.addAll([value.from, value.to]); - } - - return allModules.length; - } - - Future>> _detectDependencyCycles( - List currentPath, { - required int maxDepth, - }) async { - if (currentPath.hasCycle()) { - return [currentPath]; - } - - if (currentPath.length - 1 > maxDepth) { - return []; - } - - final last = currentPath.last; - final nextOptions = _moduleDependencies.where((dep) => dep.from == last.to); - - final resultsFutures = nextOptions.map( - (next) => _detectDependencyCycles( - List.from(currentPath)..add(next), - maxDepth: maxDepth, - ), - ); - - return (await Future.wait(resultsFutures)).flatten(); - } - - @override - String toString() => _moduleDependencies.map((d) => d.toString()).join('\n'); -} - -extension CycleDetection on List { - List path() => map((dep) => dep.from).toList()..add(last.to); - - bool hasCycle() { - final allModules = path(); - return allModules.length > allModules.toSet().length; - } -} diff --git a/cyclic_dependency_checks/pubspec.lock b/cyclic_dependency_checks/pubspec.lock deleted file mode 100644 index b75b57b..0000000 --- a/cyclic_dependency_checks/pubspec.lock +++ /dev/null @@ -1,365 +0,0 @@ -# Generated by pub -# See https://dart.dev/tools/pub/glossary#lockfile -packages: - _fe_analyzer_shared: - dependency: transitive - description: - name: _fe_analyzer_shared - sha256: eb376e9acf6938204f90eb3b1f00b578640d3188b4c8a8ec054f9f479af8d051 - url: "https://pub.dev" - source: hosted - version: "64.0.0" - analyzer: - dependency: transitive - description: - name: analyzer - sha256: "69f54f967773f6c26c7dcb13e93d7ccee8b17a641689da39e878d5cf13b06893" - url: "https://pub.dev" - source: hosted - version: "6.2.0" - args: - dependency: transitive - description: - name: args - sha256: eef6c46b622e0494a36c5a12d10d77fb4e855501a91c1b9ef9339326e58f0596 - url: "https://pub.dev" - source: hosted - version: "2.4.2" - async: - dependency: transitive - description: - name: async - sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" - url: "https://pub.dev" - source: hosted - version: "2.11.0" - boolean_selector: - dependency: transitive - description: - name: boolean_selector - sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" - url: "https://pub.dev" - source: hosted - version: "2.1.1" - collection: - dependency: transitive - description: - name: collection - sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a - url: "https://pub.dev" - source: hosted - version: "1.18.0" - convert: - dependency: transitive - description: - name: convert - sha256: "0f08b14755d163f6e2134cb58222dd25ea2a2ee8a195e53983d57c075324d592" - url: "https://pub.dev" - source: hosted - version: "3.1.1" - coverage: - dependency: transitive - description: - name: coverage - sha256: "2fb815080e44a09b85e0f2ca8a820b15053982b2e714b59267719e8a9ff17097" - url: "https://pub.dev" - source: hosted - version: "1.6.3" - crypto: - dependency: transitive - description: - name: crypto - sha256: ff625774173754681d66daaf4a448684fb04b78f902da9cb3d308c19cc5e8bab - url: "https://pub.dev" - source: hosted - version: "3.0.3" - file: - dependency: transitive - description: - name: file - sha256: "5fc22d7c25582e38ad9a8515372cd9a93834027aacf1801cf01164dac0ffa08c" - url: "https://pub.dev" - source: hosted - version: "7.0.0" - frontend_server_client: - dependency: transitive - description: - name: frontend_server_client - sha256: "408e3ca148b31c20282ad6f37ebfa6f4bdc8fede5b74bc2f08d9d92b55db3612" - url: "https://pub.dev" - source: hosted - version: "3.2.0" - glob: - dependency: transitive - description: - name: glob - sha256: "0e7014b3b7d4dac1ca4d6114f82bf1782ee86745b9b42a92c9289c23d8a0ab63" - url: "https://pub.dev" - source: hosted - version: "2.1.2" - http_multi_server: - dependency: transitive - description: - name: http_multi_server - sha256: "97486f20f9c2f7be8f514851703d0119c3596d14ea63227af6f7a481ef2b2f8b" - url: "https://pub.dev" - source: hosted - version: "3.2.1" - http_parser: - dependency: transitive - description: - name: http_parser - sha256: "2aa08ce0341cc9b354a498388e30986515406668dbcc4f7c950c3e715496693b" - url: "https://pub.dev" - source: hosted - version: "4.0.2" - io: - dependency: transitive - description: - name: io - sha256: "2ec25704aba361659e10e3e5f5d672068d332fc8ac516421d483a11e5cbd061e" - url: "https://pub.dev" - source: hosted - version: "1.0.4" - js: - dependency: transitive - description: - name: js - sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 - url: "https://pub.dev" - source: hosted - version: "0.6.7" - logging: - dependency: transitive - description: - name: logging - sha256: "623a88c9594aa774443aa3eb2d41807a48486b5613e67599fb4c41c0ad47c340" - url: "https://pub.dev" - source: hosted - version: "1.2.0" - matcher: - dependency: transitive - description: - name: matcher - sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e" - url: "https://pub.dev" - source: hosted - version: "0.12.16" - meta: - dependency: transitive - description: - name: meta - sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3" - url: "https://pub.dev" - source: hosted - version: "1.9.1" - mime: - dependency: transitive - description: - name: mime - sha256: e4ff8e8564c03f255408decd16e7899da1733852a9110a58fe6d1b817684a63e - url: "https://pub.dev" - source: hosted - version: "1.0.4" - node_preamble: - dependency: transitive - description: - name: node_preamble - sha256: "6e7eac89047ab8a8d26cf16127b5ed26de65209847630400f9aefd7cd5c730db" - url: "https://pub.dev" - source: hosted - version: "2.0.2" - package_config: - dependency: transitive - description: - name: package_config - sha256: "1c5b77ccc91e4823a5af61ee74e6b972db1ef98c2ff5a18d3161c982a55448bd" - url: "https://pub.dev" - source: hosted - version: "2.1.0" - path: - dependency: transitive - description: - name: path - sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917" - url: "https://pub.dev" - source: hosted - version: "1.8.3" - pool: - dependency: transitive - description: - name: pool - sha256: "20fe868b6314b322ea036ba325e6fc0711a22948856475e2c2b6306e8ab39c2a" - url: "https://pub.dev" - source: hosted - version: "1.5.1" - pub_semver: - dependency: transitive - description: - name: pub_semver - sha256: "40d3ab1bbd474c4c2328c91e3a7df8c6dd629b79ece4c4bd04bee496a224fb0c" - url: "https://pub.dev" - source: hosted - version: "2.1.4" - shelf: - dependency: transitive - description: - name: shelf - sha256: ad29c505aee705f41a4d8963641f91ac4cee3c8fad5947e033390a7bd8180fa4 - url: "https://pub.dev" - source: hosted - version: "1.4.1" - shelf_packages_handler: - dependency: transitive - description: - name: shelf_packages_handler - sha256: "89f967eca29607c933ba9571d838be31d67f53f6e4ee15147d5dc2934fee1b1e" - url: "https://pub.dev" - source: hosted - version: "3.0.2" - shelf_static: - dependency: transitive - description: - name: shelf_static - sha256: a41d3f53c4adf0f57480578c1d61d90342cd617de7fc8077b1304643c2d85c1e - url: "https://pub.dev" - source: hosted - version: "1.1.2" - shelf_web_socket: - dependency: transitive - description: - name: shelf_web_socket - sha256: "9ca081be41c60190ebcb4766b2486a7d50261db7bd0f5d9615f2d653637a84c1" - url: "https://pub.dev" - source: hosted - version: "1.0.4" - source_map_stack_trace: - dependency: transitive - description: - name: source_map_stack_trace - sha256: "84cf769ad83aa6bb61e0aa5a18e53aea683395f196a6f39c4c881fb90ed4f7ae" - url: "https://pub.dev" - source: hosted - version: "2.1.1" - source_maps: - dependency: transitive - description: - name: source_maps - sha256: "708b3f6b97248e5781f493b765c3337db11c5d2c81c3094f10904bfa8004c703" - url: "https://pub.dev" - source: hosted - version: "0.10.12" - source_span: - dependency: transitive - description: - name: source_span - sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" - url: "https://pub.dev" - source: hosted - version: "1.10.0" - stack_trace: - dependency: transitive - description: - name: stack_trace - sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" - url: "https://pub.dev" - source: hosted - version: "1.11.1" - stream_channel: - dependency: transitive - description: - name: stream_channel - sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7 - url: "https://pub.dev" - source: hosted - version: "2.1.2" - string_scanner: - dependency: transitive - description: - name: string_scanner - sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" - url: "https://pub.dev" - source: hosted - version: "1.2.0" - term_glyph: - dependency: transitive - description: - name: term_glyph - sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 - url: "https://pub.dev" - source: hosted - version: "1.2.1" - test: - dependency: "direct dev" - description: - name: test - sha256: "9b0dd8e36af4a5b1569029949d50a52cb2a2a2fdaa20cebb96e6603b9ae241f9" - url: "https://pub.dev" - source: hosted - version: "1.24.6" - test_api: - dependency: transitive - description: - name: test_api - sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" - url: "https://pub.dev" - source: hosted - version: "0.6.1" - test_core: - dependency: transitive - description: - name: test_core - sha256: "4bef837e56375537055fdbbbf6dd458b1859881f4c7e6da936158f77d61ab265" - url: "https://pub.dev" - source: hosted - version: "0.5.6" - typed_data: - dependency: transitive - description: - name: typed_data - sha256: facc8d6582f16042dd49f2463ff1bd6e2c9ef9f3d5da3d9b087e244a7b564b3c - url: "https://pub.dev" - source: hosted - version: "1.3.2" - vm_service: - dependency: transitive - description: - name: vm_service - sha256: "0fae432c85c4ea880b33b497d32824b97795b04cdaa74d270219572a1f50268d" - url: "https://pub.dev" - source: hosted - version: "11.9.0" - watcher: - dependency: transitive - description: - name: watcher - sha256: "3d2ad6751b3c16cf07c7fca317a1413b3f26530319181b37e3b9039b84fc01d8" - url: "https://pub.dev" - source: hosted - version: "1.1.0" - web_socket_channel: - dependency: transitive - description: - name: web_socket_channel - sha256: d88238e5eac9a42bb43ca4e721edba3c08c6354d4a53063afaa568516217621b - url: "https://pub.dev" - source: hosted - version: "2.4.0" - webkit_inspection_protocol: - dependency: transitive - description: - name: webkit_inspection_protocol - sha256: "67d3a8b6c79e1987d19d848b0892e582dbb0c66c57cc1fef58a177dd2aa2823d" - url: "https://pub.dev" - source: hosted - version: "1.2.0" - yaml: - dependency: transitive - description: - name: yaml - sha256: "75769501ea3489fca56601ff33454fe45507ea3bfb014161abc3b43ae25989d5" - url: "https://pub.dev" - source: hosted - version: "3.1.2" -sdks: - dart: ">=3.0.5 <4.0.0" diff --git a/cyclic_dependency_checks/pubspec.yaml b/cyclic_dependency_checks/pubspec.yaml deleted file mode 100644 index 0114528..0000000 --- a/cyclic_dependency_checks/pubspec.yaml +++ /dev/null @@ -1,8 +0,0 @@ -name: cyclic_dependency_checks -description: Cyclic Dependency checks for dart projects - -environment: - sdk: '>=3.0.5 <4.0.0' - -dev_dependencies: - test: ^1.24.5 diff --git a/cyclic_dependency_checks/scripts/generate_big_codebase.dart b/cyclic_dependency_checks/scripts/generate_big_codebase.dart deleted file mode 100644 index 2b534d0..0000000 --- a/cyclic_dependency_checks/scripts/generate_big_codebase.dart +++ /dev/null @@ -1,34 +0,0 @@ -import 'dart:io'; -import 'dart:math'; - -void main() async { - const alphabet = 'abcdefghijklmnopqrstuvwxyz'; - - final letters = List.generate( - alphabet.length, - (i) => alphabet.substring(i, i + 1), - ); - - final packagePath = 'test_resources/example_big_codebase'; - - String randomLetter() => letters[Random().nextInt(letters.length - 1)]; - - final libDir = Directory('$packagePath/lib'); - if (await libDir.exists()) { - await libDir.delete(recursive: true); - } - - for (final letter1 in letters) { - for (final letter2 in letters) { - var dirPath = '$packagePath/lib/$letter1/$letter2'; - var filePath = '$dirPath/file.dart'; - - await Directory(dirPath).create(recursive: true); - - await File(filePath).writeAsString( - "import 'package:example_big_codebase/${randomLetter()}/${randomLetter()}/file.dart';\n" - "import 'package:example_big_codebase/${randomLetter()}/${randomLetter()}/file.dart';\n", - ); - } - } -} diff --git a/cyclic_dependency_checks/test/cycle_detector_test.dart b/cyclic_dependency_checks/test/cycle_detector_test.dart deleted file mode 100644 index fc388e5..0000000 --- a/cyclic_dependency_checks/test/cycle_detector_test.dart +++ /dev/null @@ -1,26 +0,0 @@ -import 'package:cyclic_dependency_checks/cycle_detection/cycle_detector.dart'; -import 'package:test/test.dart'; - -void main() { - test('in codebase with no cycles', () async { - final result = await CycleDetector().detect( - 'test_resources/example_codebase_no_cycles', - ); - expect(result, hasLength(0)); - }); - - test('in codebase with cycles', () async { - final result = await CycleDetector().detect( - 'test_resources/example_codebase_with_cycles', - ); - expect(result.length, greaterThan(0)); - }); - - test('big codebase', () async { - final result = await CycleDetector().detect( - 'test_resources/example_big_codebase', - maxDepth: 8, - ); - expect(result.length, greaterThanOrEqualTo(0)); - }); -} diff --git a/cyclic_dependency_checks/test_resources/example_big_codebase/.gitignore b/cyclic_dependency_checks/test_resources/example_big_codebase/.gitignore deleted file mode 100644 index a65b417..0000000 --- a/cyclic_dependency_checks/test_resources/example_big_codebase/.gitignore +++ /dev/null @@ -1 +0,0 @@ -lib diff --git a/cyclic_dependency_checks/test_resources/example_big_codebase/pubspec.lock b/cyclic_dependency_checks/test_resources/example_big_codebase/pubspec.lock deleted file mode 100644 index 75e83e6..0000000 --- a/cyclic_dependency_checks/test_resources/example_big_codebase/pubspec.lock +++ /dev/null @@ -1,5 +0,0 @@ -# Generated by pub -# See https://dart.dev/tools/pub/glossary#lockfile -packages: {} -sdks: - dart: ">=3.0.5 <4.0.0" diff --git a/cyclic_dependency_checks/test_resources/example_big_codebase/pubspec.yaml b/cyclic_dependency_checks/test_resources/example_big_codebase/pubspec.yaml deleted file mode 100644 index 17ca45b..0000000 --- a/cyclic_dependency_checks/test_resources/example_big_codebase/pubspec.yaml +++ /dev/null @@ -1,4 +0,0 @@ -name: example_big_codebase - -environment: - sdk: '>=3.0.5 <4.0.0' diff --git a/cyclic_dependency_checks/test_resources/example_codebase_no_cycles/lib/feature_a/a.dart b/cyclic_dependency_checks/test_resources/example_codebase_no_cycles/lib/feature_a/a.dart deleted file mode 100644 index 862a0b2..0000000 --- a/cyclic_dependency_checks/test_resources/example_codebase_no_cycles/lib/feature_a/a.dart +++ /dev/null @@ -1 +0,0 @@ -import 'package:example_codebase_no_cycles/feature_b/b.dart'; diff --git a/cyclic_dependency_checks/test_resources/example_codebase_no_cycles/lib/feature_b/b.dart b/cyclic_dependency_checks/test_resources/example_codebase_no_cycles/lib/feature_b/b.dart deleted file mode 100644 index afc54a2..0000000 --- a/cyclic_dependency_checks/test_resources/example_codebase_no_cycles/lib/feature_b/b.dart +++ /dev/null @@ -1 +0,0 @@ -import 'package:example_codebase_no_cycles/feature_c/c.dart'; diff --git a/cyclic_dependency_checks/test_resources/example_codebase_no_cycles/lib/feature_c/c.dart b/cyclic_dependency_checks/test_resources/example_codebase_no_cycles/lib/feature_c/c.dart deleted file mode 100644 index e69de29..0000000 diff --git a/cyclic_dependency_checks/test_resources/example_codebase_no_cycles/pubspec.lock b/cyclic_dependency_checks/test_resources/example_codebase_no_cycles/pubspec.lock deleted file mode 100644 index 75e83e6..0000000 --- a/cyclic_dependency_checks/test_resources/example_codebase_no_cycles/pubspec.lock +++ /dev/null @@ -1,5 +0,0 @@ -# Generated by pub -# See https://dart.dev/tools/pub/glossary#lockfile -packages: {} -sdks: - dart: ">=3.0.5 <4.0.0" diff --git a/cyclic_dependency_checks/test_resources/example_codebase_no_cycles/pubspec.yaml b/cyclic_dependency_checks/test_resources/example_codebase_no_cycles/pubspec.yaml deleted file mode 100644 index 2d73bf7..0000000 --- a/cyclic_dependency_checks/test_resources/example_codebase_no_cycles/pubspec.yaml +++ /dev/null @@ -1,4 +0,0 @@ -name: example_codebase_no_cycles - -environment: - sdk: '>=3.0.5 <4.0.0' diff --git a/cyclic_dependency_checks/test_resources/example_codebase_with_cycles/lib/feature_a/a.dart b/cyclic_dependency_checks/test_resources/example_codebase_with_cycles/lib/feature_a/a.dart deleted file mode 100644 index 05f6e55..0000000 --- a/cyclic_dependency_checks/test_resources/example_codebase_with_cycles/lib/feature_a/a.dart +++ /dev/null @@ -1 +0,0 @@ -import 'package:example_codebase_with_cycles/feature_b/b.dart'; diff --git a/cyclic_dependency_checks/test_resources/example_codebase_with_cycles/lib/feature_b/b.dart b/cyclic_dependency_checks/test_resources/example_codebase_with_cycles/lib/feature_b/b.dart deleted file mode 100644 index c39cac6..0000000 --- a/cyclic_dependency_checks/test_resources/example_codebase_with_cycles/lib/feature_b/b.dart +++ /dev/null @@ -1 +0,0 @@ -import 'package:example_codebase_with_cycles/feature_c/c.dart'; diff --git a/cyclic_dependency_checks/test_resources/example_codebase_with_cycles/lib/feature_c/c.dart b/cyclic_dependency_checks/test_resources/example_codebase_with_cycles/lib/feature_c/c.dart deleted file mode 100644 index ccd9766..0000000 --- a/cyclic_dependency_checks/test_resources/example_codebase_with_cycles/lib/feature_c/c.dart +++ /dev/null @@ -1 +0,0 @@ -import 'package:example_codebase_with_cycles/feature_a/a.dart'; diff --git a/cyclic_dependency_checks/test_resources/example_codebase_with_cycles/pubspec.lock b/cyclic_dependency_checks/test_resources/example_codebase_with_cycles/pubspec.lock deleted file mode 100644 index 75e83e6..0000000 --- a/cyclic_dependency_checks/test_resources/example_codebase_with_cycles/pubspec.lock +++ /dev/null @@ -1,5 +0,0 @@ -# Generated by pub -# See https://dart.dev/tools/pub/glossary#lockfile -packages: {} -sdks: - dart: ">=3.0.5 <4.0.0" diff --git a/cyclic_dependency_checks/test_resources/example_codebase_with_cycles/pubspec.yaml b/cyclic_dependency_checks/test_resources/example_codebase_with_cycles/pubspec.yaml deleted file mode 100644 index bf3ec5f..0000000 --- a/cyclic_dependency_checks/test_resources/example_codebase_with_cycles/pubspec.yaml +++ /dev/null @@ -1,4 +0,0 @@ -name: example_codebase_with_cycles - -environment: - sdk: '>=3.0.5 <4.0.0' diff --git a/weather_app/Tasks.mk b/weather_app/Tasks.mk new file mode 100644 index 0000000..fb85fa0 --- /dev/null +++ b/weather_app/Tasks.mk @@ -0,0 +1,9 @@ +.PHONY: weather_app/install weather_app/check + +weather_app/install: + cd weather_app; flutter pub get + +weather_app/check: + cd weather_app; dart format lib --line-length 100 --set-exit-if-changed + cd weather_app; flutter test + cd weather_app; dart run cyclic_dependency_checks . diff --git a/weather_app/pubspec.lock b/weather_app/pubspec.lock index fa611af..f0b8bd8 100644 --- a/weather_app/pubspec.lock +++ b/weather_app/pubspec.lock @@ -49,6 +49,15 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.5" + cyclic_dependency_checks: + dependency: "direct main" + description: + path: "." + ref: "release/0.1.0" + resolved-ref: "3a36c1245006f53f7a38271a2afd17b868bec2d0" + url: "https://github.com/dam5s/cyclic_dependency_checks.git" + source: git + version: "0.1.0" fake_async: dependency: transitive description: diff --git a/weather_app/pubspec.yaml b/weather_app/pubspec.yaml index c00c52c..3fe40b0 100644 --- a/weather_app/pubspec.yaml +++ b/weather_app/pubspec.yaml @@ -11,6 +11,11 @@ dependencies: flutter: sdk: flutter + cyclic_dependency_checks: + git: + url: https://github.com/dam5s/cyclic_dependency_checks.git + ref: release/0.1.0 + cupertino_icons: ^1.0.2 http: ^1.1.0 provider: ^6.0.5