-
Notifications
You must be signed in to change notification settings - Fork 26
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
Add check to use periods at the end of error messages #88
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const RuleTester = require('eslint').RuleTester; | ||
const rule = require('../use-periods-for-error-messages'); | ||
const message = require('../CONST').MESSAGE.USE_PERIODS_ERROR_MESSAGES; | ||
|
||
const ruleTester = new RuleTester({ | ||
parserOptions: { | ||
ecmaVersion: 6, | ||
sourceType: 'module', | ||
}, | ||
}); | ||
|
||
const goodExample = ` | ||
error: { | ||
testMessage: 'This is a test message.' | ||
} | ||
`; | ||
|
||
const badExample = ` | ||
error: { | ||
testMessage: 'This is a test message' | ||
} | ||
`; | ||
|
||
ruleTester.run('use-periods-for-error-messages', rule, { | ||
valid: [ | ||
{ | ||
code: goodExample, | ||
}, | ||
], | ||
invalid: [ | ||
{ | ||
code: badExample, | ||
errors: [{ | ||
message, | ||
}], | ||
}, | ||
], | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
require('lodash/get'); | ||
const message = require('./CONST').MESSAGE.USE_PERIODS_ERROR_MESSAGES; | ||
|
||
module.exports = { | ||
create(context) { | ||
return { | ||
Property(node) { | ||
if (!node.key || node.key.name !== 'error' || !node.value || node.value.type !== 'ObjectExpression') { | ||
return; | ||
} | ||
node.value.properties.forEach((property) => { | ||
if (!property.value || property.value.type !== 'Literal' || typeof property.value.value !== 'string') { | ||
return; | ||
} | ||
const errorMessage = property.value.value; | ||
if (!errorMessage.endsWith('.')) { | ||
context.report({ | ||
node: property, | ||
message, | ||
fix: function (fixer) { | ||
const lastChar = errorMessage[errorMessage.length - 1]; | ||
const fixedMessage = lastChar === '.' ? errorMessage : `${errorMessage}.`; | ||
return fixer.replaceText(property.value, `'${fixedMessage}'`); | ||
} | ||
}); | ||
} | ||
}); | ||
}, | ||
}; | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "eslint-config-expensify", | ||
"version": "2.0.44", | ||
"version": "2.0.45", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to change this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, we need to increase the version and then use it in Expensify/App. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think that's how it works, check other PRs. that step seems to be automated. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's there in above PR. It needs to be done in package-lock.json also, added there as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you check recent PRs? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it, OSBotify bot will update it. Updated. |
||
"description": "Expensify's ESLint configuration following our style guide", | ||
"main": "index.js", | ||
"repository": { | ||
|
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 don't see this condition working while having it inside
if (!errorMessage.endsWith('.')) {
, am i missing anything?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.
Yes, the check was not needed. Updated it.