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

first cut at catching property name collisions during file output #273

Merged
merged 7 commits into from
May 28, 2019

Conversation

chazzmoney
Copy link
Collaborator

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.

@chazzmoney
Copy link
Collaborator Author

chazzmoney commented May 17, 2019

This is NOT ready. Two issues:

  1. I changed the basic example to cause errors so you can see what the output looks like
  2. If y'all like it, I need to add tests

@chazzmoney
Copy link
Collaborator Author

@didoo and @dbanksdesign let me know what you think

Copy link
Member

@dbanksdesign dbanksdesign left a 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',
Copy link
Member

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.`;
Copy link
Member

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 ');
Copy link
Member

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?

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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?

Copy link
Member

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) => {
Copy link
Member

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?

Copy link
Collaborator Author

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) => {
Copy link
Member

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.

Copy link
Collaborator Author

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 ');
Copy link
Member

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)([
Copy link
Member

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.

Copy link
Collaborator Author

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.

Copy link
Member

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.

@@ -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;
Copy link
Member

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.

Copy link
Collaborator Author

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.

Copy link
Member

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.

Copy link
Collaborator Author

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;
Copy link
Contributor

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

Copy link
Collaborator Author

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';
Copy link
Contributor

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

Copy link
Collaborator Author

@chazzmoney chazzmoney May 20, 2019

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.

Copy link
Member

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

changed to in-line

@didoo
Copy link
Contributor

didoo commented May 20, 2019

I have just added a couple of comments, but overall seems good to me.

Copy link
Member

@dbanksdesign dbanksdesign left a comment

Choose a reason for hiding this comment

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

LGTM! :shipit:

@chazzmoney
Copy link
Collaborator Author

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

@dbanksdesign
Copy link
Member

Can you take a look at the test failure on travis?

@chazzmoney
Copy link
Collaborator Author

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.

@dbanksdesign
Copy link
Member

You could use chalk methods in the test? Or how are we testing other console outputs that use chalk?

@chazzmoney
Copy link
Collaborator Author

Yeah, exactly what I did. Let me know if you still approve and we can MERGE BABY MERGE. 🤓

Copy link
Member

@dbanksdesign dbanksdesign left a comment

Choose a reason for hiding this comment

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

LGTM! :shipit:

@dbanksdesign dbanksdesign merged commit 9a40407 into master May 28, 2019
@dbanksdesign dbanksdesign deleted the catch-file-output-prop-name-collisions branch May 28, 2019 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants