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

feat: migrate all message to messageId #482

Merged
merged 2 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion rules/always-return.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ module.exports = {
additionalProperties: false,
},
],
messages: {
thenShouldThrow: 'Each then() should return a value or throw',
},
},
create(context) {
const options = context.options[0] || {}
Expand Down Expand Up @@ -242,7 +245,7 @@ module.exports = {
const branch = funcInfo.branchInfoMap[id]
if (!branch.good) {
context.report({
message: 'Each then() should return a value or throw',
messageId: 'thenShouldThrow',
scagood marked this conversation as resolved.
Show resolved Hide resolved
node: branch.node,
})
}
Expand Down
5 changes: 4 additions & 1 deletion rules/avoid-new.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@ module.exports = {
url: getDocsUrl('avoid-new'),
},
schema: [],
messages: {
avoidNew: 'Avoid creating new promises.',
},
},
create(context) {
return {
NewExpression(node) {
if (node.callee.name === 'Promise') {
context.report({ node, message: 'Avoid creating new promises.' })
context.report({ node, messageId: 'avoidNew' })
}
},
}
Expand Down
5 changes: 4 additions & 1 deletion rules/no-nesting.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ module.exports = {
url: getDocsUrl('no-nesting'),
},
schema: [],
messages: {
avoidNesting: 'Avoid nesting promises.',
},
},
create(context) {
/**
Expand Down Expand Up @@ -112,7 +115,7 @@ module.exports = {

context.report({
node: node.callee.property,
message: 'Avoid nesting promises.',
messageId: 'avoidNesting',
})
},
}
Expand Down
5 changes: 4 additions & 1 deletion rules/no-new-statics.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ module.exports = {
},
fixable: 'code',
schema: [],
messages: {
avoidNewStatic: "Avoid calling 'new' on 'Promise.{{ name }}()'",
},
},
create(context) {
return {
Expand All @@ -23,7 +26,7 @@ module.exports = {
) {
context.report({
node,
message: "Avoid calling 'new' on 'Promise.{{ name }}()'",
messageId: 'avoidNewStatic',
data: { name: node.callee.property.name },
fix(fixer) {
return fixer.replaceTextRange(
Expand Down
5 changes: 4 additions & 1 deletion rules/no-promise-in-callback.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ module.exports = {
url: getDocsUrl('no-promise-in-callback'),
},
schema: [],
messages: {
avoidPromiseInCallback: 'Avoid using promises inside of callbacks.',
},
},
create(context) {
return {
Expand All @@ -34,7 +37,7 @@ module.exports = {
if (getAncestors(context, node).some(isInsideCallback)) {
context.report({
node: node.callee,
message: 'Avoid using promises inside of callbacks.',
messageId: 'avoidPromiseInCallback',
})
}
},
Expand Down
5 changes: 4 additions & 1 deletion rules/no-return-in-finally.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ module.exports = {
url: getDocsUrl('no-return-in-finally'),
},
schema: [],
messages: {
avoidReturnInFinally: 'No return in finally',
},
},
create(context) {
return {
Expand All @@ -35,7 +38,7 @@ module.exports = {
) {
context.report({
node: node.callee.property,
message: 'No return in finally',
messageId: 'avoidReturnInFinally',
})
}
}
Expand Down
12 changes: 8 additions & 4 deletions rules/param-names.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ module.exports = {
additionalProperties: false,
},
],
messages: {
resolveParamNames:
'Promise constructor parameters must be named to match "{{ resolvePattern }}"',
rejectParamNames:
'Promise constructor parameters must be named to match "{{ rejectPattern }}"',
},
},
create(context) {
const options = context.options[0] || {}
Expand All @@ -45,8 +51,7 @@ module.exports = {
if (resolveParamName && !resolvePattern.test(resolveParamName)) {
context.report({
node: params[0],
message:
'Promise constructor parameters must be named to match "{{ resolvePattern }}"',
messageId: 'resolveParamNames',
data: {
resolvePattern: resolvePattern.source,
},
Expand All @@ -56,8 +61,7 @@ module.exports = {
if (rejectParamName && !rejectPattern.test(rejectParamName)) {
context.report({
node: params[1],
message:
'Promise constructor parameters must be named to match "{{ rejectPattern }}"',
messageId: 'rejectParamNames',
data: {
rejectPattern: rejectPattern.source,
},
Expand Down
5 changes: 4 additions & 1 deletion rules/prefer-await-to-then.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ module.exports = {
url: getDocsUrl('prefer-await-to-then'),
},
schema: [],
messages: {
preferWaitToCallback: 'Prefer await to then()/catch()/finally().',
scagood marked this conversation as resolved.
Show resolved Hide resolved
},
},
create(context) {
/** Returns true if node is inside yield or await expression. */
Expand Down Expand Up @@ -52,7 +55,7 @@ module.exports = {
) {
context.report({
node: node.property,
message: 'Prefer await to then()/catch()/finally().',
messageId: 'preferWaitToCallback',
})
}
},
Expand Down
17 changes: 11 additions & 6 deletions rules/valid-params.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ module.exports = {
url: getDocsUrl('valid-params'),
},
schema: [],
messages: {
requireOneOptionalArgument:
'Promise.{{ name }}() requires 0 or 1 arguments, but received {{ numArgs }}',
requireOneArgument:
'Promise.{{ name }}() requires 1 argument, but received {{ numArgs }}',
requireTwoOptionalArgument:
'Promise.{{ name }}() requires 1 or 2 arguments, but received {{ numArgs }}',
},
},
create(context) {
return {
Expand All @@ -30,8 +38,7 @@ module.exports = {
if (numArgs > 1) {
context.report({
node,
message:
'Promise.{{ name }}() requires 0 or 1 arguments, but received {{ numArgs }}',
messageId: 'requireOneOptionalArgument',
data: { name, numArgs },
})
}
Expand All @@ -40,8 +47,7 @@ module.exports = {
if (numArgs < 1 || numArgs > 2) {
context.report({
node,
message:
'Promise.{{ name }}() requires 1 or 2 arguments, but received {{ numArgs }}',
messageId: 'requireTwoOptionalArgument',
scagood marked this conversation as resolved.
Show resolved Hide resolved
data: { name, numArgs },
})
}
Expand All @@ -55,8 +61,7 @@ module.exports = {
if (numArgs !== 1) {
context.report({
node,
message:
'Promise.{{ name }}() requires 1 argument, but received {{ numArgs }}',
messageId: 'requireOneArgument',
data: { name, numArgs },
})
}
Expand Down