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

strongest lint rules, fixed all lint and dart 2 warnings #33

Merged
merged 4 commits into from
Feb 28, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
35 changes: 17 additions & 18 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ analyzer:
linter:
rules:
# Style: Declare method return types.
# override with // ignore: always_declare_return_types
- always_declare_return_types

# Style: Separate the control structure expression from its statement.
Expand All @@ -30,22 +29,22 @@ linter:
- always_require_non_null_named_parameters

# Style: Specify type annotations.
# - always_specify_types # really annoying for local vars
- always_specify_types

# Style: Annotate overridden members
- annotate_overrides

# Style: Avoid annotating with dynamic when not required.
# - avoid_annotating_with_dynamic
- avoid_annotating_with_dynamic

# Style: Avoid using as.
# - avoid_as # comment overrides don't seem to work
- avoid_as

# Style: Avoid catches without on clauses.
# - avoid_catches_without_on_clauses
- avoid_catches_without_on_clauses

# Style: Don't explicitly catch Error or types that implement it.
# - avoid_catching_errors # Consider uncommenting under Dart 2
- avoid_catching_errors

# Style: Avoid defining a class that contains only static members.
- avoid_classes_with_only_static_members
Expand Down Expand Up @@ -78,7 +77,7 @@ linter:
- avoid_slow_async_io

# Style: Avoid annotating types for function expression parameters.
# - avoid_types_on_closure_parameters
# - avoid_types_on_closure_parameters # conflicts with always_specify_types

# Style: Avoid defining unused paramters in constructors.
- avoid_unused_constructor_parameters
Expand All @@ -90,7 +89,7 @@ linter:
- camel_case_types

# Style: Cascade consecutive method invocations on the same reference.
# - cascade_invocations
- cascade_invocations

# Error: Cancel instances of dart.async.StreamSubscription.
- cancel_subscriptions
Expand All @@ -102,7 +101,7 @@ linter:
- comment_references

# Style: Prefer using lowerCamelCase for constant names.
# - constant_identifier_names
- constant_identifier_names

# Error: Avoid control flow in finally block.
- control_flow_in_finally
Expand Down Expand Up @@ -153,13 +152,13 @@ linter:
- no_duplicate_case_values

# Style: Name non-constant identifiers using lowerCamelCase.
# - non_constant_identifier_names # UiFactories will lint
- non_constant_identifier_names # UiFactories will lint

# Style: Omit type annotations for local variables.
# - omit_local_variable_types
# - omit_local_variable_types # conflicts with always_specify_types

# Style: Avoid defining a one-member abstract class when a simple function will do.
# - one_member_abstracts
- one_member_abstracts

# Style: Only throw instances of classes extending either Exception or Error
- only_throw_errors
Expand All @@ -177,7 +176,7 @@ linter:
- package_prefixed_library_names

# Style: Don't reassign references to parameters of functions or methods.
# - parameter_assignments # team preference
- parameter_assignments

# Style: Use adjacent strings to concatenate string literals.
- prefer_adjacent_string_concatenation
Expand Down Expand Up @@ -213,13 +212,13 @@ linter:
- prefer_contains

# Style: Use => for short members whose body is a single return statement.
# - prefer_expression_function_bodies
- prefer_expression_function_bodies

# Style: Private field could be final.
# - prefer_final_fields
- prefer_final_fields

# Style: Prefer final for variable declaration if reference is not reassigned.
# - prefer_final_locals # Noisy, people use var a lot
- prefer_final_locals # Noisy, people use var a lot

# Style: Use forEach to only apply a function to all the elements.
- prefer_foreach
Expand All @@ -246,10 +245,10 @@ linter:
- prefer_typing_uninitialized_variables

# Style: Document all public members
# - public_member_api_docs # really annoying for lifecycle methods
- public_member_api_docs

# Style: Property getter recursively returns itself.
# - recursive_getters # seems buggy
- recursive_getters

# Style: Prefer to use /// for doc comments
- slash_for_doc_comments
Expand Down
102 changes: 50 additions & 52 deletions lib/font_face_observer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class _FontRecord {
uses = 0;
groupUses.clear();
}
StringBuffer groupData = new StringBuffer();
final StringBuffer groupData = new StringBuffer();
for (String group in groupUses.keys) {
groupData.write('$group(${groupUses[group]}) ');
}
Expand Down Expand Up @@ -230,8 +230,9 @@ class FontFaceObserver {
_group = _isNullOrWhitespace(group) ? defaultGroup : group;
if (family != null) {
family = family.trim();
bool hasStartQuote = family.startsWith('"') || family.startsWith("'");
bool hasEndQuote = family.endsWith('"') || family.endsWith("'");
final bool hasStartQuote =
family.startsWith('"') || family.startsWith("'");
final bool hasEndQuote = family.endsWith('"') || family.endsWith("'");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer final

if (hasStartQuote && hasEndQuote) {
family = family.substring(1, family.length - 1);
}
Expand All @@ -244,24 +245,21 @@ class FontFaceObserver {
/// The default group used for a font if none is specified.
static const String defaultGroup = 'default';
static Future<FontLoadResult> _adobeBlankLoadedFuture = _loadAdobeBlank();
static Future<FontLoadResult> _loadAdobeBlank() {
return (new FontFaceObserver(adobeBlankFamily, group: adobeBlankFamily))
.load(adobeBlankFontBase64Url);
}
static Future<FontLoadResult> _loadAdobeBlank() =>
new FontFaceObserver(adobeBlankFamily, group: adobeBlankFamily)
.load(adobeBlankFontBase64Url);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer arrow functions for single statement return functions


/// Returns the font keys for all currently loaded fonts
static Iterable<String> getLoadedFontKeys() {
return _loadedFonts.keys.toSet();
}
static Iterable<String> getLoadedFontKeys() => _loadedFonts.keys.toSet();

/// Returns the groups that the currently loaded fonts are in.
/// There will not be duplicate group entries if there are multiple fonts
/// in the same group.
static Iterable<String> getLoadedGroups() {
Set<String> loadedGroups = new Set<String>();
final Set<String> loadedGroups = new Set<String>();

void getLoadedGroups(String k) {
_FontRecord record = _loadedFonts[k];
final _FontRecord record = _loadedFonts[k];
loadedGroups.addAll(record.groupUses.keys);
}

Expand All @@ -286,10 +284,10 @@ class FontFaceObserver {

// parallel arrays of keys and groups that go along with the keys at the
// same indexes.
List<String> keysToRemove = <String>[];
List<_FontRecord> records = <_FontRecord>[];
final List<String> keysToRemove = <String>[];
final List<_FontRecord> records = <_FontRecord>[];
for (String k in _loadedFonts.keys.toList()) {
_FontRecord record = _loadedFonts[k];
final _FontRecord record = _loadedFonts[k];
// wait for the load future to complete
await record.futureLoadResult;

Expand Down Expand Up @@ -319,7 +317,7 @@ class FontFaceObserver {
/// key/group combo was not found.
static Future<bool> unload(String key, String group) async {
if (_loadedFonts.containsKey(key)) {
_FontRecord record = _loadedFonts[key];
final _FontRecord record = _loadedFonts[key];
// wait for the load future to complete
await record.futureLoadResult;

Expand Down Expand Up @@ -361,7 +359,7 @@ class FontFaceObserver {
return _result.future;
}

_FontRecord record = _loadedFonts[key];
final _FontRecord record = _loadedFonts[key];
if (record == null) {
return new FontLoadResult(isLoaded: false, didTimeout: false);
}
Expand All @@ -372,7 +370,7 @@ class FontFaceObserver {

// Since browsers may not load a font until it is actually used (lazily loaded)
// We add this span to trigger the browser to load the font when used
String _key = '_ffo_dummy_${key}';
final String _key = '_ffo_dummy_${key}';
Element dummy = document.getElementById(_key);
if (dummy == null) {
dummy = new SpanElement()
Expand Down Expand Up @@ -410,17 +408,17 @@ class FontFaceObserver {
/// Load the font into the browser given a url that could be a network url
/// or a pre-built data or blob url.
Future<FontLoadResult> load(String url) async {
_FontRecord record = _load(url);
final _FontRecord record = _load(url);
if (_result.isCompleted) {
return _result.future;
}

try {
FontLoadResult flr = await check();
final FontLoadResult flr = await check();
if (flr.isLoaded) {
return _result.future;
}
} catch (x) {
} on Exception {
// On errors, make sure the font is unloaded
_unloadFont(key, record);
return new FontLoadResult(isLoaded: false, didTimeout: false);
Expand All @@ -438,12 +436,12 @@ class FontFaceObserver {
/// initial use count of 1.
_FontRecord _load(String url) {
StyleElement styleElement;
String _key = key;
final String _key = key;
_FontRecord record;
if (_loadedFonts.containsKey(_key)) {
record = _loadedFonts[_key];
} else {
String rule = '''
final String rule = '''
@font-face {
font-family: "${family}";
font-style: ${style};
Expand All @@ -470,7 +468,7 @@ class FontFaceObserver {
/// Generates the CSS style string to be used when detecting a font load
/// for a given [family] at a certain [cssSize] (default 100px)
String _getStyle(String family, {String cssSize: '100px'}) {
String _stretch = supportsStretch ? stretch : '';
final String _stretch = supportsStretch ? stretch : '';
return '$style $weight $_stretch $cssSize $family';
}

Expand Down Expand Up @@ -515,7 +513,7 @@ class FontFaceObserver {
num fallbackWidthSerif = -1;
num fallbackWidthMonospace = -1;

Element container = document.createElement('div');
final Element container = document.createElement('div');

// Internal check function
// -----------------------
Expand Down Expand Up @@ -567,43 +565,45 @@ class FontFaceObserver {
}

// This ensures the scroll direction is correct.
container.dir = 'ltr';
// add class names for tracking nodes if they leak (and for testing)
container.className = '$fontFaceObserverTempClassname _ffo_container';
container
..dir = 'ltr'
// add class names for tracking nodes if they leak (and for testing)
..className = '$fontFaceObserverTempClassname _ffo_container';
_rulerSansSerif.setFont(_getStyle('sans-serif'));
_rulerSerif.setFont(_getStyle('serif'));
_rulerMonospace.setFont(_getStyle('monospace'));

container.append(_rulerSansSerif.element);
container.append(_rulerSerif.element);
container.append(_rulerMonospace.element);
container
..append(_rulerSansSerif.element)
..append(_rulerSerif.element)
..append(_rulerMonospace.element);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer cascades


document.body.append(container);

fallbackWidthSansSerif = _rulerSansSerif.getWidth();
fallbackWidthSerif = _rulerSerif.getWidth();
fallbackWidthMonospace = _rulerMonospace.getWidth();

_rulerSansSerif.onResize((num width) {
widthSansSerif = width;
_checkWidths();
});

_rulerSansSerif.setFont(_getStyle('"$family",AdobeBlank,sans-serif'));

_rulerSerif.onResize((num width) {
widthSerif = width;
_checkWidths();
});

_rulerSerif.setFont(_getStyle('"$family",AdobeBlank,serif'));
_rulerSansSerif
..onResize((num width) {
widthSansSerif = width;
_checkWidths();
})
..setFont(_getStyle('"$family",AdobeBlank,sans-serif'));

_rulerMonospace.onResize((num width) {
widthMonospace = width;
_checkWidths();
});
_rulerSerif
..onResize((num width) {
widthSerif = width;
_checkWidths();
})
..setFont(_getStyle('"$family",AdobeBlank,serif'));

_rulerMonospace.setFont(_getStyle('"$family",AdobeBlank,monospace'));
_rulerMonospace
..onResize((num width) {
widthMonospace = width;
_checkWidths();
})
..setFont(_getStyle('"$family",AdobeBlank,monospace'));

// The above code will trigger a scroll event when the font loads
// but if the document is hidden, it may not, so we will periodically
Expand Down Expand Up @@ -641,6 +641,4 @@ class FontFaceObserver {
}
}

bool _isNullOrWhitespace(String s) {
return s == null || s.trim().isEmpty;
}
bool _isNullOrWhitespace(String s) => s == null || s.trim().isEmpty;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙁

2 changes: 1 addition & 1 deletion lib/src/adobe_blank.dart

Large diffs are not rendered by default.

Loading