Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package update #75

Merged
merged 3 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/contributors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ jobs:
contributor_list:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: cjdenio/contributor_list@master
- name: Checkout Repository
uses: actions/checkout@v4
- name: Contributor List
uses: cjdenio/contributor_list@master
with:
commit_message: 📝 Update contributors list
max_contributors: 10
27 changes: 17 additions & 10 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,31 @@ on:
- pull_request

jobs:
dartfmt:
format:
runs-on: ubuntu-latest
container:
image: google/dart:latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Setup Flutter SDK
uses: subosito/flutter-action@v2
with:
sdk: stable
- name: Run pub get
run: dart pub get
working-directory: ./example/example_app
- name: Run format
run: dartfmt --dry-run --set-exit-if-changed .
run: dart format --set-exit-if-changed .

import_sorter:
runs-on: ubuntu-latest
container:
image: google/dart:latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Setup Dart SDK
uses: dart-lang/setup-dart@v1
with:
sdk: stable
- name: Run import_sorter
run: |
pub get
pub run import_sorter:main --exit-if-changed
dart pub get
dart run import_sorter:main --exit-if-changed
14 changes: 8 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ jobs:
build:
runs-on: ubuntu-latest

container:
image: google/dart:latest

steps:
- uses: actions/checkout@v2
- name: Checkout Repository
uses: actions/checkout@v4
- name: Setup Dart SDK
uses: dart-lang/setup-dart@v1
with:
sdk: stable
- name: Install dependencies
run: pub get
run: dart pub get
- name: Run tests
run: pub run test
run: dart pub run test
19 changes: 19 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
include: package:lints/recommended.yaml


analyzer:
errors:
prefer_const_constructors: error
annotate_overrides: error
prefer_single_quotes: error
sort_pub_dependencies: error
invalid_annotation_target: ignore

linter:
rules:
prefer_double_quotes: false
sort_pub_dependencies: true
annotate_overrides: true
file_names: false
overridden_fields: false
prefer_single_quotes: true
30 changes: 15 additions & 15 deletions bin/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void main(List<String> args) {
Package name is one factor used to identify project imports
Dependencies/dev_dependencies names are used to identify package imports
*/
final pubspecYamlFile = File('${currentPath}/pubspec.yaml');
final pubspecYamlFile = File('$currentPath/pubspec.yaml');
final pubspecYaml = loadYaml(pubspecYamlFile.readAsStringSync());

// Getting all dependencies and project package name
Expand All @@ -40,13 +40,13 @@ void main(List<String> args) {
final stopwatch = Stopwatch();
stopwatch.start();

final pubspecLockFile = File('${currentPath}/pubspec.lock');
final pubspecLockFile = File('$currentPath/pubspec.lock');
final pubspecLock = loadYaml(pubspecLockFile.readAsStringSync());
dependencies.addAll(pubspecLock['packages'].keys);

var emojis = false;
var noComments = false;
final ignored_files = [];
final ignoredFiles = [];

// Reading from config in pubspec.yaml safely
if (!argResults.contains('--ignore-config')) {
Expand All @@ -55,7 +55,7 @@ void main(List<String> args) {
if (config.containsKey('emojis')) emojis = config['emojis'];
if (config.containsKey('comments')) noComments = !config['comments'];
if (config.containsKey('ignored_files')) {
ignored_files.addAll(config['ignored_files']);
ignoredFiles.addAll(config['ignored_files']);
}
}
}
Expand All @@ -69,16 +69,16 @@ void main(List<String> args) {
final dartFiles = files.dartFiles(currentPath, args);
final containsFlutter = dependencies.contains('flutter');
final containsRegistrant = dartFiles
.containsKey('${currentPath}/lib/generated_plugin_registrant.dart');
.containsKey('$currentPath/lib/generated_plugin_registrant.dart');

stdout.writeln('contains flutter: ${containsFlutter}');
stdout.writeln('contains registrant: ${containsRegistrant}');
stdout.writeln('contains flutter: $containsFlutter');
stdout.writeln('contains registrant: $containsRegistrant');

if (containsFlutter && containsRegistrant) {
dartFiles.remove('${currentPath}/lib/generated_plugin_registrant.dart');
dartFiles.remove('$currentPath/lib/generated_plugin_registrant.dart');
}

for (final pattern in ignored_files) {
for (final pattern in ignoredFiles) {
dartFiles.removeWhere((key, _) =>
RegExp(pattern).hasMatch(key.replaceFirst(currentPath, '')));
}
Expand Down Expand Up @@ -108,19 +108,19 @@ void main(List<String> args) {

// Outputting results
if (sortedFiles.length > 1) {
stdout.write("\n");
stdout.write('\n');
}
for (int i = 0; i < sortedFiles.length; i++) {
final file = dartFiles[sortedFiles[i]];
stdout.write(
'${sortedFiles.length == 1 ? '\n' : ''}┃ ${i == sortedFiles.length - 1 ? '┗' : '┣'}━━ ${success} Sorted imports for ${file?.path.replaceFirst(currentPath, '')}/');
'${sortedFiles.length == 1 ? '\n' : ''}┃ ${i == sortedFiles.length - 1 ? '┗' : '┣'}━━ $success Sorted imports for ${file?.path.replaceFirst(currentPath, '')}/');
String filename = file!.path.split(Platform.pathSeparator).last;
stdout.write(filename + "\n");
stdout.write('$filename\n');
}

if (sortedFiles.length == 0) {
stdout.write("\n");
if (sortedFiles.isEmpty) {
stdout.write('\n');
}
stdout.write(
'┗━━ ${success} Sorted ${sortedFiles.length} files in ${stopwatch.elapsed.inSeconds}.${stopwatch.elapsedMilliseconds} seconds\n');
'┗━━ $success Sorted ${sortedFiles.length} files in ${stopwatch.elapsed.inSeconds}.${stopwatch.elapsedMilliseconds} seconds\n');
}
4 changes: 4 additions & 0 deletions example/example_app/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
analyzer:
errors:
unused_import: ignore
unnecessary_import: ignore
118 changes: 0 additions & 118 deletions example/example_app/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,127 +10,9 @@ import 'package:flutter/painting.dart';
import 'package:flutter/physics.dart';

// 📦 Package imports:
import 'package:flutter_gen/gen_l10n/translations.dart';
import 'package:intl/intl.dart';
import 'package:mdi/mdi.dart';
import 'package:provider/provider.dart';

// 🌎 Project imports:
import 'package:example_app/anotherFile2.dart';
import 'anotherFile.dart';

void main() {
runApp(MyApp());
}

class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
primarySwatch: Colors.blue,
// This makes the visual density adapt to the platform that you run
// the app on. For desktop platforms, the controls will be smaller and
// closer together (more dense) than on mobile platforms.
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}

class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);

// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
// how it looks.

// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".

final String title;

@override
_MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;

void _incrementCounter() {
setState(() {
// This call to setState tells the Flutter framework that something has
// changed in this State, which causes it to rerun the build method below
// so that the display can reflect the updated values. If we changed
// _counter without calling setState(), then the build method would not be
// called again, and so nothing would appear to happen.
_counter++;
});
}

@override
Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return Scaffold(
appBar: AppBar(
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(widget.title),
),
body: Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child: Column(
// Column is also a layout widget. It takes a list of children and
// arranges them vertically. By default, it sizes itself to fit its
// children horizontally, and tries to be as tall as its parent.
//
// Invoke "debug painting" (press "p" in the console, choose the
// "Toggle Debug Paint" action from the Flutter Inspector in Android
// Studio, or the "Toggle Debug Paint" command in Visual Studio Code)
// to see the wireframe for each widget.
//
// Column has various properties to control how it sizes itself and
// how it positions its children. Here we use mainAxisAlignment to
// center the children vertically; the main axis here is the vertical
// axis because Columns are vertical (the cross axis would be
// horizontal).
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
9 changes: 4 additions & 5 deletions example/example_app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,17 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1

environment:
sdk: '>=2.7.0 <3.0.0'
sdk: ">=2.12.0 <4.0.0"

dependencies:
flutter:
sdk: flutter
provider: ^4.0.5
mdi: ^2.0.0
intl: ^0.16.1
provider: ^6.1.1
intl: ^0.19.0

# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.3
cupertino_icons: ^1.0.6

dev_dependencies:
flutter_test:
Expand Down
4 changes: 2 additions & 2 deletions lib/files.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ Map<String, File> dartFiles(String currentPath, List<String> args) {
var onlyCertainFiles = false;
for (final arg in args) {
if (!onlyCertainFiles) {
onlyCertainFiles = arg.endsWith("dart");
onlyCertainFiles = arg.endsWith('dart');
}
}

if (onlyCertainFiles) {
final patterns = args.where((arg) => !arg.startsWith("-"));
final patterns = args.where((arg) => !arg.startsWith('-'));
final filesToKeep = <String, File>{};

for (final fileName in dartFiles.keys) {
Expand Down
10 changes: 5 additions & 5 deletions lib/sort.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'dart:io';
/// at index 1
ImportSortData sortImports(
List<String> lines,
String package_name,
String packageName,
bool emojis,
bool exitIfChanged,
bool noComments, {
Expand Down Expand Up @@ -55,7 +55,7 @@ ImportSortData sortImports(
dartImports.add(lines[i]);
} else if (lines[i].contains('package:flutter/')) {
flutterImports.add(lines[i]);
} else if (lines[i].contains('package:$package_name/')) {
} else if (lines[i].contains('package:$packageName/')) {
projectImports.add(lines[i]);
} else if (lines[i].contains('package:')) {
packageImports.add(lines[i]);
Expand Down Expand Up @@ -152,11 +152,11 @@ ImportSortData sortImports(
sortedLines.add('');

final sortedFile = sortedLines.join('\n');
final original = lines.join('\n') + '\n';
final original = '${lines.join('\n')}\n';
if (exitIfChanged && original != sortedFile) {
if (filePath != null) {
stdout.writeln(
'\n┗━━🚨 File ${filePath} does not have its imports sorted.');
stdout
.writeln('\n┗━━🚨 File $filePath does not have its imports sorted.');
}
exit(1);
}
Expand Down
Loading
Loading