-
Notifications
You must be signed in to change notification settings - Fork 24
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
Prettier rules gives Unexpected token #40
Comments
I think linter is parsing files with wrong format, because I have other errors which indicate parser is not considering json values with parameters correctly :
|
@azuken I'm actually facing the exact same issue, have you manage to resolve this somehow? |
@Siggnja No, I have tried to search for invisible chars, special chars, file format, line endings, and the result is the same. So I hope that authors will have an answer ! |
@azuken I added the folder that includes my i18n json files to .prettierIgnore, that at least removes the errors. Not happy about this though but at least I can continue with my day. |
@azuken @Siggnja You are seeing errors from additional
|
@apawson I've just tested your solution with another eslintrc file, and syntax errors still appears.
But prettier errors are gone ! |
@azuken Based on the error message, I'd guess that somewhere in your code you are referencing the translation without passing the value for - t('forThe')
+ t('forThe', { date: '17th of May' }) |
I've verified in my code and I use this translation only once, and I have my parameter passed :
All other translations with errors are correctly implemented. It seems that the plugin does not recognize parameter with double brackets. If i set only one pair of brackets, linter is ok, but translation does not insert parameter... |
@azuken https://github.com/godaddy/eslint-plugin-i18n-json doesn't, by default, support the See: #7 (comment) As noted ☝️ , you can write a custom validator like this: https://github.com/godaddy/eslint-plugin-i18n-json/tree/master/examples/custom-message-syntax Feel free to steal this one which I wrote for my own const validate = (message = '') => {
if (!(message || '').trim()) {
throw new SyntaxError('Message is Empty.');
}
if (typeof message !== 'string') {
throw new TypeError('Message must be a String.');
}
if (
(message.includes('{') || message.includes('}')) &&
!/{{ ?(?:- |\w+?)(, ?)?\w+? ?}}/g.test(message)
) {
throw new SyntaxError(
'Interpolation error. See: https://www.i18next.com/misc/json-format',
);
}
if (message.includes('$t(') && !/\$t\([\w]+:\w+(?:\.\w+)*\)/g.test(message)) {
throw new SyntaxError(
'Nesting error. See: https://www.i18next.com/misc/json-format',
);
}
};
module.exports = validate; |
@apawson Okay I didn't saw that i18next was not compatible. Works like a charm now, thank you ! For future readers, add sample code ⬆️ into a file named const path = require('path')
module.exports = {
extends: ['plugin:i18n-json/recommended'],
rules: {
'i18n-json/valid-message-syntax': [
2,
{
syntax: path.resolve('./custom-message-syntax'),
},
],
},
} |
Hello,
I've installed this plugin for a React Native project, and everything is working so far, but one error by translation file remains, and I don't know what is wrong.
eslint --fix --format node_modules/eslint-plugin-i18n-json/formatter.js --ext .json src/locales
is reporting me
I've checked file format, line ending, invisible characters, error still appears.
Here is my .eslintrc.js config file :
and my .prettierrc.js file :
The text was updated successfully, but these errors were encountered: