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

Conversation

robbecker-wf
Copy link
Member

@robbecker-wf robbecker-wf commented Feb 20, 2018

Overview

Turned on even more lint rules and fixed lint. Also fixed any Dart 2 warnings using the Dart 2 dev branch. This library should now work seamlessly with Dart 2.

Testing

@aviary2-wf
Copy link

aviary2-wf commented Feb 20, 2018

Module Findings

No security relevant content detected. Please review for security relevance and request security review as needed.

pubspec.yaml Outdated
@@ -5,7 +5,7 @@ author: Rob Becker <rob.becker@workiva.com>
homepage: https://github.com/Workiva/font_face_observer

environment:
sdk: '>=1.22.1 <2.0.0'
sdk: '>=1.22.1 <= 2.0.0'
Copy link
Member Author

@robbecker-wf robbecker-wf Feb 20, 2018

Choose a reason for hiding this comment

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

allow Dart 2 .. this will need updating to allow > 2.0.0

Copy link
Member Author

Choose a reason for hiding this comment

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

nah... I'll wait until a stable build of dart 2 before making this call.

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

}
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

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

lib/support.dart Outdated
@@ -91,8 +93,9 @@ bool _supportsStretch() {
bool _supportsNativeFontLoading() {
bool supports = true;
try {
// ignore: unnecessary_statements
Copy link
Member Author

Choose a reason for hiding this comment

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

including this ignore because even though this looks like the statement doesn't do anything, we want to try the accessor to trigger an exception in browsers that don't support FontFace API

Copy link

@andrewalbers-wf andrewalbers-wf Feb 23, 2018

Choose a reason for hiding this comment

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

Ah, could you add a comment to the test explaining what this document.fonts.status line is for? It wouldn't make immediate sense to me, and I'd be extra confused if I found it following this ignore: unnecessary_statements line.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure! It's similar to the above function _supportsStretch where it tries to use the API and catches the exception that gets thrown if that API isn't available in the browser. I'll add a comment to this effect.

elements.forEach( (Element el) => print('${el.tagName}.${el.className}'));
for (Element el in elements) {
print('${el.tagName}.${el.className}');
}
Copy link
Member Author

Choose a reason for hiding this comment

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

replace anonymous forEach with for..in

Choose a reason for hiding this comment

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

👍

@codecov-wf
Copy link

codecov-wf commented Feb 20, 2018

Current coverage is 88.66% (diff: 93.22%)

Merging #33 into master will decrease coverage by 0.78%

@@             master        #33   diff @@
==========================================
  Files             4          4          
  Lines           294        300     +6   
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
+ Hits            263        266     +3   
- Misses           31         34     +3   
  Partials          0          0          

Sunburst

Diff Coverage File Path
••••••• 75% lib/support.dart
••••••••• 94% lib/font_face_observer.dart
•••••••••• 100% lib/src/ruler.dart

Powered by Codecov. Last update 2da22ae...b001864

@andrewalbers-wf
Copy link

Hmm, using final in all these places seems weird to me. Is it a performance boost or something? I could imagine coming to this code later and wanting to update a local variable, but wondering if that would go against the intention of the author who put final on it.

@@ -120,8 +120,7 @@ class Ruler {

_collapsible.append(_collapsibleInner);
_expandable.append(_expandableInner);
element.append(_collapsible);
element.append(_expandable);
element..append(_collapsible)..append(_expandable);

Choose a reason for hiding this comment

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

This... does not seem more readable to me, but 🤷‍♂️

Copy link
Member Author

Choose a reason for hiding this comment

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

dart format usually puts cascades on their own new line .. not sure why it chose to 1-line this one.

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.

🙁

Copy link

@andrewalbers-wf andrewalbers-wf left a comment

Choose a reason for hiding this comment

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

I don't really care for all the style changes these lints require, but I don't have a super strong opinion. No problems found, LGTM +1

@robbecker-wf
Copy link
Member Author

All the finals are because of the prefer_final_fields and prefer_final_locals. They report that the compiler can optimize the code, but it doesn't say exactly what that means.

Declaring variables as final when possible is a good practice because it helps avoid accidental reassignments and allows the compiler to do optimizations.

@andrewalbers-wf
Copy link

+1

@tomconnell-wf
Copy link
Member

+10

✅ CI Passed
✅ Examples still work

@tomconnell-wf
Copy link
Member

Quality Review Approval: QA +1

  • Testing Instructions
  • Dev +1's
  • Dev/QA +10 detailing what was tested
  • Tests created, updated, or explained if not present
  • All CI checks pass (Smithy, Shipyard, Skynet)
    @Workiva/release-management-pp - Rosie, will you automerge?

@rmconsole-wf rmconsole-wf merged commit 04430a2 into master Feb 28, 2018
@rmconsole-wf rmconsole-wf deleted the lintless_and_dart2 branch February 28, 2018 16:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants