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

fix: Permit single-line JSON comments #1361

Merged
merged 1 commit into from
Aug 29, 2018
Merged

Conversation

Rob--W
Copy link
Member

@Rob--W Rob--W commented Aug 27, 2018

Fixes #1352 .

@Rob--W Rob--W requested a review from rpl August 27, 2018 12:09
@coveralls
Copy link

coveralls commented Aug 27, 2018

Coverage Status

Coverage remained the same at 100.0% when pulling 62632ca on Rob--W:json-comments into 9ec3a5e on mozilla:master.

package.json Outdated
@@ -75,7 +75,6 @@
"sign-addon": "0.3.1",
"source-map-support": "0.5.3",
"stream-to-promise": "2.2.0",
"strip-json-comments": "2.0.1",
Copy link
Member

Choose a reason for hiding this comment

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

@Rob--W Do you mind to bring back the "strip-json-comments" dependency in this PR?

"strip-json-comments" removes the comments stripped by replacing them with white spaces, which is nice because it ensures that any JSON parsing error is going to point to the right place of the original JSON file (which is also confirmed by the change you have to apply in the "tests/unit/test-util/test.manifest.js" test case below to make it pass).

It is true that "strip-json-comments" supports both line (// ...) and multiline comments (/* ... */) whereas Firefox only supports line comments, but it is not a big deal and web-ext lint has its own validation rules and it is reporting the expected error on a json file that contains multiline comments (whereas web-ext strips the comments only to be able to read the JSON file and retrieve some information from that file).

I would prefer #384 to ensure that an extension is completely valid before running it (which also have an open PR, #817, currently it has some conflicts but I'm going to take a look at it asap)

@Rob--W
Copy link
Member Author

Rob--W commented Aug 29, 2018

@rpl Done.

Copy link
Member

@rpl rpl left a comment

Choose a reason for hiding this comment

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

@Rob--W Thanks, the change looks great!
it only misses a small additional test case, and then it is ready to go

} catch (error) {
throw new UsageError(
`Error reading messages.json file at ${messageFile}: ${error}`);
}

try {
messageData = parseJSON(String(messageContents), messageFile);
messageData = parseJSON(stripJsonComments(messageContents), messageFile);
Copy link
Member

Choose a reason for hiding this comment

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

@Rob--W Do you mind to add an additional test case for this fix in 'tests/unit/test-cmd/test.build.js'?

Strip comments from _locales/*/messages.json.

And set an explicit encoding in readFile so that the return value is a
string instead of a Buffer.
@Rob--W
Copy link
Member Author

Rob--W commented Aug 29, 2018

@rpl Done again.

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.

3 participants