-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat(eslint-plugin): add rule object-curly-spacing #1884
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(eslint-plugin): add rule object-curly-spacing #1884
Conversation
Thanks for the PR, @Kiikurage! typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community. The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately. Thanks again! 🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint. As a thank you, your profile/company logo will be added to our main README which receives thousands of unique visitors per day. |
Codecov Report
@@ Coverage Diff @@
## master #1884 +/- ##
==========================================
+ Coverage 94.49% 94.53% +0.03%
==========================================
Files 162 163 +1
Lines 7471 7521 +50
Branches 2139 2154 +15
==========================================
+ Hits 7060 7110 +50
Misses 178 178
Partials 233 233
|
@bradzacher Wat would need to happen before this PR can be reviewed (besides perhaps @Kiikurage rebasing the branch on master because of the merge conflict)? |
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.
code as it stands mostly looks good to me.
I wonder if you could save all of the code duplication by "hacking" at the base rule?
eg:
TypeLiteral(node): void {
rule.ObjectExpression({
...node,
properties: node.members,
} as any);
}
## Rule Details | ||
|
||
This rule extends the base [`eslint/object-curly-spacing`](https://eslint.org/docs/rules/object-curly-spacing) rule. | ||
It supports all options and features of the base rule. |
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 supports all options and features of the base rule. | |
It adds support for TypeScript's object types |
messages: { | ||
requireSpaceBefore: "A space is required before '{{token}}'.", | ||
requireSpaceAfter: "A space is required after '{{token}}'.", | ||
unexpectedSpaceBefore: "There should be no space before '{{token}}'.", | ||
unexpectedSpaceAfter: "There should be no space after '{{token}}'.", | ||
}, |
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 need to redeclare if you're not changing the messages.
messages: { | |
requireSpaceBefore: "A space is required before '{{token}}'.", | |
requireSpaceAfter: "A space is required after '{{token}}'.", | |
unexpectedSpaceBefore: "There should be no space before '{{token}}'.", | |
unexpectedSpaceAfter: "There should be no space after '{{token}}'.", | |
}, | |
messages: baseRule.messages, |
const spaced = context.options[0] === 'always', | ||
sourceCode = context.getSourceCode(); |
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.
nit
const spaced = context.options[0] === 'always', | |
sourceCode = context.getSourceCode(); | |
const spaced = context.options[0] === 'always'; | |
const sourceCode = context.getSourceCode(); |
* @param {Object} option The option to exclude. | ||
* @returns {boolean} Whether or not the property is excluded. |
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.
nitpick
* @param {Object} option The option to exclude. | |
* @returns {boolean} Whether or not the property is excluded. | |
* @param option The option to exclude. | |
* @returns Whether or not the property is excluded. |
const first = sourceCode.getFirstToken(node)!, | ||
last = getClosingBraceOfObject(node)!, | ||
second = sourceCode.getTokenAfter(first, { includeComments: true })!, | ||
penultimate = sourceCode.getTokenBefore(last, { |
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.
nit
const first = sourceCode.getFirstToken(node)!, | |
last = getClosingBraceOfObject(node)!, | |
second = sourceCode.getTokenAfter(first, { includeComments: true })!, | |
penultimate = sourceCode.getTokenBefore(last, { | |
const first = sourceCode.getFirstToken(node)!; | |
const last = getClosingBraceOfObject(node)!; | |
const second = sourceCode.getTokenAfter(first, { includeComments: true })!; | |
const penultimate = sourceCode.getTokenBefore(last, { |
added new extended rule
object-curly-spacing
Fixes #1784