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

Refactor ftl parsing to use fluent-syntax/compat. #1888

Merged
merged 2 commits into from
Mar 13, 2018

Conversation

EnTeQuAk
Copy link
Contributor

@EnTeQuAk EnTeQuAk commented Mar 8, 2018

  • Also fixes package.json to use and define correct webpack dependencies
  • Updates yarn.lock

Do not merge yet, blocked by projectfluent/fluent.js#164

Fixes #1789

.travis.yml Outdated
@@ -7,6 +7,8 @@ script:
- yarn run test-ci
- yarn run build
- yarn run lint
before_install:
- yarn config set ignore-engines true
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Temporary until projectfluent/fluent.js#164 get's merged

Copy link

Choose a reason for hiding this comment

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

Isn't this actually a better temporary solution to this problem than projectfluent/fluent.js#164? Assuming the longer term solution is to drop the support for Node 6 in addons-linter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, it's not since the linter is being installed by users via web-ext - https://github.com/mozilla/web-ext and a strict engine in package.json doesn't allow the user to install the linter via npm or yarn.

.travis.yml Outdated
@@ -7,6 +7,8 @@ script:
- yarn run test-ci
- yarn run build
- yarn run lint
before_install:
- yarn config set ignore-engines true
Copy link

Choose a reason for hiding this comment

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

Isn't this actually a better temporary solution to this problem than projectfluent/fluent.js#164? Assuming the longer term solution is to drop the support for Node 6 in addons-linter.

@@ -18,30 +19,47 @@ export default class FluentParser {
this.isValid = null;
}

getLineAndColumnFromSpan(span) {
Copy link

Choose a reason for hiding this comment

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

This looks like a job for lineOffset and columnOffset exported by fluent-syntax :)

https://github.com/projectfluent/fluent.js/blob/fee9cbf347c4edecaaf60f757da6c515110f2356/fluent-syntax/src/index.js#L17-L36

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I didn't see those helpers yet. The code is quite similar, I'll use the upstream version then, thanks for the hint!

package.json Outdated
@@ -79,7 +79,8 @@
"request": "2.83.0",
"sinon": "4.4.2",
"tar": "4.4.0",
"webpack": "3.10.0",
"webpack": "4.0.1",
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like it was actually webpack 3.x that was used before, webpack-grunt doesn't have webpack 4.x release supported yet (it's merged into master though so should only be a matter of time 🎉)

I also addressed this in #1889, but maybe this has all the changes required to go to webpack 4.x?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just merged or going to merge the removal of webpack-grunt dependency so we'll be able to update to webpack 4.x soon. But step by step…

I'll back out the package.json changes here anyway.

This now got rebased to fluent-syntax 0.6.5 which re-adds node 6 LTS
compatibility.

Fixes #1789
@EnTeQuAk
Copy link
Contributor Author

EnTeQuAk commented Mar 8, 2018

Rebased to master, removed earlier hacks, rebased to fluent-syntax 0.6.5 which adds node6 support.

@rpl if you have a moment, this should be ready for review.

},
],
},
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I primarily removed these since I essentially only copy the upstream tree into parsedData and that tree is huge and would bloat up our tests. There is one test that verifies things at a very basic level so I thought that has to suffice.

@EnTeQuAk EnTeQuAk requested a review from rpl March 8, 2018 17:14
Copy link
Contributor

@tofumatt tofumatt left a comment

Choose a reason for hiding this comment

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

Works for me. As mentioned I don't really know fluent all that well but the code seems fine save for my magic-constant-phobia.

Maybe worth a look from someone else who knows fluent better but then if it doesn't break all the other tests I guess it's 👍

this.parsedData[id] = entries[id];
});
resource.body.forEach((entry) => {
if (entry.type === 'Junk') {
Copy link
Contributor

Choose a reason for hiding this comment

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

If fluent-syntax provides a constant for this it'd be nice, magic constants just make me scared.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately not, I might push a follow-up PR to clean this up a bit and think about better tests.

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

👍 on importing the Junk class and turning this into entry instanceof Junk in a follow up as @zbraniecki pointed out.

val: undefined,
},
});
expect(parser.parsedData.key67.attributes[0].value.elements[0].value).toEqual(
Copy link
Contributor

Choose a reason for hiding this comment

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

These tests read foreign to me without context but I have no idea how fluent works... I'm gonna trust you on them 😄

@EnTeQuAk
Copy link
Contributor Author

I'm going to merge this, if there's any more comments I'm very happy to update the implementation but to land this this week I'm merging and releasing a new version of the linter for now.

It's not breaking the tests and actually fixing something so it can't be too bad 🙈

@EnTeQuAk EnTeQuAk merged commit 0c7870c into master Mar 13, 2018
@EnTeQuAk EnTeQuAk deleted the 1789-use-fluent-syntax branch March 13, 2018 18:05
const errorData = {
...messages.FLUENT_INVALID,
file: this.filename,
// normalize newlines and flatten the message a bit.
description: error.message.replace(/(?:\n(?:\s*))+/g, ' '),
description: entry.annotations[0].message,
Copy link
Member

Choose a reason for hiding this comment

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

We have already assigned entry.annotations[0] to annotation at line 36, this could just be annotation.message.

};

this.collector.addError(errorData);
});
}
} else if (entry.id !== undefined) {
Copy link
Member

Choose a reason for hiding this comment

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

if entry.id can be both null or undefined this should be entry.id != null.

this.parsedData[id] = entries[id];
});
resource.body.forEach((entry) => {
if (entry.type === 'Junk') {
Copy link
Member

Choose a reason for hiding this comment

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

👍 on importing the Junk class and turning this into entry instanceof Junk in a follow up as @zbraniecki pointed out.

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.

Fluent Linter should use fluent-syntax, not fluent
6 participants