Skip to content

Commit

Permalink
Add lint rules (#8)
Browse files Browse the repository at this point in the history
Add lint rules
  • Loading branch information
svprdga authored Sep 14, 2021
1 parent 6d9d76a commit d44b263
Show file tree
Hide file tree
Showing 15 changed files with 58 additions and 103 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# torch_light

[![style: lint](https://img.shields.io/badge/style-lint-4BC0F5.svg)](https://pub.dev/packages/lint)

A simple Flutter plugin to enable/disable the device torch light.

## Plugin status
Expand Down
6 changes: 6 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
include: package:lint/analysis_options.yaml

linter:
rules:
sort_pub_dependencies: false
avoid_classes_with_only_static_members: false
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.android.tools.build:gradle:3.5.4'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand Down
4 changes: 2 additions & 2 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 29
compileSdkVersion 30

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
Expand All @@ -40,7 +40,7 @@ android {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.svprdga.torchlight.torch_light_example"
minSdkVersion 21
targetSdkVersion 29
targetSdkVersion 30
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
Expand Down
4 changes: 2 additions & 2 deletions example/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
buildscript {
ext.kotlin_version = '1.3.50'
ext.kotlin_version = '1.5.30'
repositories {
google()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.android.tools.build:gradle:7.0.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand Down
2 changes: 1 addition & 1 deletion example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip
2 changes: 1 addition & 1 deletion example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/torch_light/ios"

SPEC CHECKSUMS:
Flutter: 50d75fe2f02b26cc09d224853bb45737f8b3214a
Flutter: 434fef37c0980e73bb6479ef766c45957d4b510c
torch_light: 682062fa12102172fa38b6b14c106d93b060f83e

PODFILE CHECKSUM: aafe91acc616949ddb318b77800a7f51bffa2a4c
Expand Down
6 changes: 3 additions & 3 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = DW967KM9ZS;
DEVELOPMENT_TEAM = A97AY86M9N;
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
Expand Down Expand Up @@ -492,7 +492,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = DW967KM9ZS;
DEVELOPMENT_TEAM = A97AY86M9N;
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
Expand Down Expand Up @@ -523,7 +523,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = DW967KM9ZS;
DEVELOPMENT_TEAM = A97AY86M9N;
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
Expand Down
8 changes: 4 additions & 4 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.8.1"
version: "2.6.1"
boolean_selector:
dependency: transitive
description:
Expand All @@ -28,7 +28,7 @@ packages:
name: charcode
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.1"
version: "1.2.0"
clock:
dependency: transitive
description:
Expand Down Expand Up @@ -92,7 +92,7 @@ packages:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.7.0"
version: "1.3.0"
path:
dependency: transitive
description:
Expand Down Expand Up @@ -146,7 +146,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.2"
version: "0.3.0"
torch_light:
dependency: "direct main"
description:
Expand Down
40 changes: 2 additions & 38 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
name: torch_light_example
description: Demonstrates how to use the torch_light plugin.

# The following line prevents the package from being accidentally published to
# pub.dev using `pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
publish_to: 'none'

environment:
sdk: ">=2.12.0 <3.0.0"
Expand All @@ -22,38 +19,5 @@ dev_dependencies:
flutter_test:
sdk: flutter

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter.
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
# To add assets to your application, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware.
# For details regarding adding assets from package dependencies, see
# https://flutter.dev/assets-and-images/#from-packages
# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.dev/custom-fonts/#from-packages
uses-material-design: true
12 changes: 6 additions & 6 deletions lib/exceptions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class EnableTorchExistentUserException implements Exception {
@override
String toString() => message != null
? "[EnableTorchExistentUserException: $message]"
: "[EnableTorchExistentUserException has received a null message]";
: "[EnableTorchExistentUserException]";
}

class EnableTorchException implements Exception {
Expand All @@ -19,7 +19,7 @@ class EnableTorchException implements Exception {
@override
String toString() => message != null
? "[EnableTorchException: $message]"
: "[EnableTorchException has received a null message]";
: "[EnableTorchException]";
}

class EnableTorchNotAvailableException implements Exception {
Expand All @@ -30,7 +30,7 @@ class EnableTorchNotAvailableException implements Exception {
@override
String toString() => message != null
? "[EnableTorchNotAvailableException: $message]"
: "[EnableTorchNotAvailableException has received a null message]";
: "[EnableTorchNotAvailableException]";
}

class DisableTorchExistentUserException implements Exception {
Expand All @@ -41,7 +41,7 @@ class DisableTorchExistentUserException implements Exception {
@override
String toString() => message != null
? "[DisableTorchExistentUserException: $message]"
: "[DisableTorchExistentUserException has received a null message]";
: "[DisableTorchExistentUserException]";
}

class DisableTorchException implements Exception {
Expand All @@ -52,7 +52,7 @@ class DisableTorchException implements Exception {
@override
String toString() => message != null
? "[DisableTorchException: $message]"
: "[DisableTorchException has received a null message]";
: "[DisableTorchException]";
}

class DisableTorchNotAvailableException implements Exception {
Expand All @@ -63,5 +63,5 @@ class DisableTorchNotAvailableException implements Exception {
@override
String toString() => message != null
? "[DisableTorchNotAvailableException: $message]"
: "[DisableTorchNotAvailableException has received a null message]";
: "[DisableTorchNotAvailableException]";
}
31 changes: 14 additions & 17 deletions lib/torch_light.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,21 @@ part 'exceptions.dart';
class TorchLight {
// ****************************** CONSTANTS ****************************** //

static const _CHANNEL_NAME = 'com.svprdga.torchlight/main';
static const _channelName = 'com.svprdga.torchlight/main';

static const NATIVE_EVENT_ENABLE_TORCH = 'enable_torch';
static const ERROR_ENABLE_TORCH_EXISTENT_USER =
static const _nativeEventEnableTorch = 'enable_torch';
static const _errorEnableTorchExistentUser =
'enable_torch_error_existent_user';
static const ERROR_ENABLE_TORCH = 'enable_torch_error';
static const ERROR_ENABLE_TORCH_NOT_AVAILABLE = 'enable_torch_not_available';
static const _errorEnableTorchNotAvailable = 'enable_torch_not_available';

static const NATIVE_EVENT_DISABLE_TORCH = 'disable_torch';
static const ERROR_DISABLE_TORCH_EXISTENT_USER =
static const _nativeEventDisableTorch = 'disable_torch';
static const _errorDisableTorchExistentUser =
'disable_torch_error_existent_user';
static const ERROR_DISABLE_TORCH = 'disable_torch_error';
static const ERROR_DISABLE_TORCH_NOT_AVAILABLE =
'disable_torch_not_available';
static const _errorDIsableTorchNotAvailable = 'disable_torch_not_available';

// ********************************* VARS ******************************** //

static const MethodChannel _channel = const MethodChannel(_CHANNEL_NAME);
static const MethodChannel _channel = MethodChannel(_channelName);

//***************************** PUBLIC METHODS *************************** //

Expand All @@ -35,12 +32,12 @@ class TorchLight {
/// Throws an [EnableTorchException] if the process encounters an error.
static Future<void> enableTorch() async {
try {
await _channel.invokeMethod(NATIVE_EVENT_ENABLE_TORCH);
await _channel.invokeMethod(_nativeEventEnableTorch);
} on PlatformException catch (e) {
switch (e.code) {
case ERROR_ENABLE_TORCH_EXISTENT_USER:
case _errorEnableTorchExistentUser:
throw EnableTorchExistentUserException(message: e.message);
case ERROR_ENABLE_TORCH_NOT_AVAILABLE:
case _errorEnableTorchNotAvailable:
throw EnableTorchNotAvailableException(message: e.message);
default:
throw EnableTorchException(message: e.message);
Expand All @@ -55,12 +52,12 @@ class TorchLight {
/// Throws a [DisableTorchException] if the process encounters an error.
static Future<void> disableTorch() async {
try {
await _channel.invokeMethod(NATIVE_EVENT_DISABLE_TORCH);
await _channel.invokeMethod(_nativeEventDisableTorch);
} on PlatformException catch (e) {
switch (e.code) {
case ERROR_DISABLE_TORCH_EXISTENT_USER:
case _errorDisableTorchExistentUser:
throw DisableTorchExistentUserException(message: e.message);
case ERROR_DISABLE_TORCH_NOT_AVAILABLE:
case _errorDIsableTorchNotAvailable:
throw DisableTorchNotAvailableException(message: e.message);
default:
throw DisableTorchException(message: e.message);
Expand Down
17 changes: 12 additions & 5 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.8.1"
version: "2.6.1"
boolean_selector:
dependency: transitive
description:
Expand All @@ -28,7 +28,7 @@ packages:
name: charcode
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.1"
version: "1.2.0"
clock:
dependency: transitive
description:
Expand Down Expand Up @@ -60,6 +60,13 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
lint:
dependency: "direct dev"
description:
name: lint
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.0"
matcher:
dependency: transitive
description:
Expand All @@ -73,7 +80,7 @@ packages:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.7.0"
version: "1.3.0"
path:
dependency: transitive
description:
Expand Down Expand Up @@ -127,7 +134,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.2"
version: "0.3.0"
typed_data:
dependency: transitive
description:
Expand All @@ -143,5 +150,5 @@ packages:
source: hosted
version: "2.1.0"
sdks:
dart: ">=2.12.0 <3.0.0"
dart: ">=2.13.0 <3.0.0"
flutter: ">=1.20.0"
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ dependencies:
dev_dependencies:
flutter_test:
sdk: flutter
lint: ^1.6.0

flutter:
plugin:
Expand Down
24 changes: 1 addition & 23 deletions test/torch_light_test.dart
Original file line number Diff line number Diff line change
@@ -1,23 +1 @@
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:torch_light/torch_light.dart';

void main() {
const MethodChannel channel = MethodChannel('torch_light');

TestWidgetsFlutterBinding.ensureInitialized();

setUp(() {
channel.setMockMethodCallHandler((MethodCall methodCall) async {
return '42';
});
});

tearDown(() {
channel.setMockMethodCallHandler(null);
});

test('getPlatformVersion', () async {
expect(await TorchLight.platformVersion, '42');
});
}
void main() {}

0 comments on commit d44b263

Please sign in to comment.