-
Notifications
You must be signed in to change notification settings - Fork 144
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
Conversation
.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 |
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.
Temporary until projectfluent/fluent.js#164 get's merged
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.
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
.
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'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 |
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.
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
.
src/parsers/fluent.js
Outdated
@@ -18,30 +19,47 @@ export default class FluentParser { | |||
this.isValid = null; | |||
} | |||
|
|||
getLineAndColumnFromSpan(span) { |
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 looks like a job for lineOffset
and columnOffset
exported by fluent-syntax
:)
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.
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", |
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.
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?
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.
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
7b43c08
to
491f9ea
Compare
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. |
0e18d2d
to
ef123e2
Compare
}, | ||
], | ||
}, | ||
}); |
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 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.
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.
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') { |
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 fluent-syntax
provides a constant for this it'd be nice, magic constants just make me scared.
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 not, I might push a follow-up PR to clean this up a bit and think about better tests.
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.
It provides a type you can test against instanceof
- https://github.com/projectfluent/fluent.js/blob/master/fluent-syntax/src/ast.js#L240
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.
👍 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( |
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.
These tests read foreign to me without context but I have no idea how fluent works... I'm gonna trust you on them 😄
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 🙈 |
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, |
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 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) { |
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 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') { |
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.
👍 on importing the Junk
class and turning this into entry instanceof Junk
in a follow up as @zbraniecki pointed out.
Do not merge yet, blocked by projectfluent/fluent.js#164Fixes #1789