-
Notifications
You must be signed in to change notification settings - Fork 566
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
first cut at catching property name collisions during file output #273
Conversation
This is NOT ready. Two issues:
|
@didoo and @dbanksdesign let me know what you think |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some minor things, overall I like it. 🙆♂️ What are your thoughts on either: moving those 50 lines in buildFile to a new file, or to a new function within that file for readability?
@@ -20,6 +20,7 @@ var GroupMessages = { | |||
RegisterTemplateDeprecationWarnings: 'Register Template Deprecation Warnings', | |||
SassMapFormatDeprecationWarnings: 'Sass Map Format Deprecation Warnings', | |||
MissingRegisterTransformErrors: 'Missing Register Transform Errors', | |||
PropertyNameCollisionWarnings: 'Property Name Collision Warnings', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are getting some real use out of the groupMessages! I never thought we'd have this many warnings and errors, but it follows our tenet to fail loudly! Super cool.
lib/buildFile.js
Outdated
|
||
if(propertyNamesCollisionCount > 0) { | ||
var propertyNamesCollisionWarnings = GroupMessages.flush(PROPERTY_NAME_COLLISION_WARNINGS).join('\n '); | ||
let title = `While building ${chalk.keyword(HIGHLIGHT_COLOR).bold(dest)}, token collisions were found; output may be unexpected.`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"output may be unexpected" love it
lib/buildFile.js
Outdated
console.log(chalk.bold.green((propertyNamesCollisionCount > 0) ? '⚠️ ' : '✔︎ ') + ' ' + destination); | ||
|
||
if(propertyNamesCollisionCount > 0) { | ||
var propertyNamesCollisionWarnings = GroupMessages.flush(PROPERTY_NAME_COLLISION_WARNINGS).join('\n '); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: you are using let
in other places but var
here, should we be consistent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should switch everything to ES6 as per #153 . I'm trying to stay aligned with the technique used in each file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Crap, nm - using both in this file. I was moving things around a bit per our conversation and didn't change after a copy and paste. Will fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ehhhhhhh.... so I just set all root level functional variables to use var and the block scoped variable to use let. Whatcha think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess that is probably fine for now, and tackle it all in #153
|
||
// Check for property name Collisions | ||
var nameCollisionObj = {}; | ||
filteredProperties.allProperties && filteredProperties.allProperties.forEach((propertyData) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this check? I think when we are constructing allProperties
it will always be at least an empty array?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately this is required. The tests do not generate allProperties at all in some cases, causing an error to throw here and the tests to fail.
lib/buildFile.js
Outdated
var WARNING_COLOR = 'darkorange'; | ||
var HIGHLIGHT_COLOR = 'orangered'; | ||
var HELP_COLOR = 'orange'; | ||
Object.keys(nameCollisionObj).map((propertyName) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change .map
here to .forEach
since we aren't actually mapping the array to some variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops. Good call.
lib/buildFile.js
Outdated
var HELP_COLOR = 'orange'; | ||
Object.keys(nameCollisionObj).map((propertyName) => { | ||
if(nameCollisionObj[propertyName].length > 1) { | ||
let collisions = nameCollisionObj[propertyName].map(properties => chalk.keyword(HIGHLIGHT_COLOR)(properties.path.join('.')) + ' ' + chalk.keyword(WARNING_COLOR)(properties.value)).join('\n '); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is a bit long and hard to read. Maybe break this into a few lines?
lib/buildFile.js
Outdated
if(propertyNamesCollisionCount > 0) { | ||
var propertyNamesCollisionWarnings = GroupMessages.flush(PROPERTY_NAME_COLLISION_WARNINGS).join('\n '); | ||
let title = `While building ${chalk.keyword(HIGHLIGHT_COLOR).bold(dest)}, token collisions were found; output may be unexpected.`; | ||
let help = chalk.keyword(HELP_COLOR)([ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe use back-ticks here since all you need the array for is to put new line characters in between each line. I like this message though. You could probably put title
and help
into a single string literal to make this cleaner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've had massive problems with formatting trying to use multiple backtick sections into each other. This was my solution.
I'm going to hold off on this change for now, and when we get everything else to a good place if you have a good suggestion maybe you can do a PR into this one - it was literally the piece that took me the longest.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, after we merge this I can try to do a cleanup PR on this area.
lib/transform/config.js
Outdated
@@ -29,6 +29,7 @@ var MISSING_TRANSFORM_ERRORS = GroupMessages.GROUP.MissingRegisterTransformError | |||
*/ | |||
function transformConfig(config, dictionary, platformName) { | |||
var to_ret = _.clone(config); | |||
to_ret.platformName = platformName; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this being used elsewhere? I can't find this being used in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No it is not. I was using it to generate the message originally, but then realized I could just use the current output stream instead of generating something unique.
I thought it made sense to have the platform name present in the platform (that data is currently not available), so I left it. I can pull to a different PR if you want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea let's pull it to a different PR, just so this one is focused on a single problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
lib/buildFile.js
Outdated
@@ -33,6 +34,8 @@ function buildFile(destination, format, platform, dictionary, filter) { | |||
if (!destination || typeof destination !== 'string') | |||
throw new Error('Please enter a valid destination'); | |||
|
|||
var dest = destination; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably I would not do this, but create a variable fullDestination
(or something similar, I am not sure about the name) which is the one used and manipulated, and leave the value destination
untouched, so it can be used directly in the construction of the title if propertyNamesCollisionCount > 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed
lib/buildFile.js
Outdated
}); | ||
|
||
var PROPERTY_NAME_COLLISION_WARNINGS = GroupMessages.GROUP.PropertyNameCollisionWarnings; | ||
var WARNING_COLOR = 'darkorange'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would not create variables just for this, at the end are just colors in Chalk, even if they are copy&pasted no big deal
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you guys like the current coloring, I can make this change. It was super painful changing colors when I was creating the output message so I used this to make it simpler.
If everyone confirms they like the output, I'll change this out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed to in-line
I have just added a couple of comments, but overall seems good to me. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Sorry, was adding the tests still - and adding them required me to change something (the key for grouping messages is now per destination). Can you peek one more time? @dbanksdesign |
Can you take a look at the test failure on travis? |
Well 💩. So apparently color coding in chalk differs on different platforms. Soooo... I dunno. I’ll come up with a way to rewrite the test. |
You could use chalk methods in the test? Or how are we testing other console outputs that use chalk? |
Yeah, exactly what I did. Let me know if you still approve and we can MERGE BABY MERGE. 🤓 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Bug found in #257, but not solving #257
Code to catch collisions in the array of properties immediately before file output.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.