Skip to content

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

Conversation

Kiikurage
Copy link

@Kiikurage Kiikurage commented Apr 11, 2020

added new extended rule object-curly-spacing

  • tests
  • docs
  • typing update

Fixes #1784

@typescript-eslint
Copy link
Contributor

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.

@Kiikurage Kiikurage changed the title feat(eslint-plugin): implement object-curly-spacing rule (#1784) feat(eslint-plugin): implement object-curly-spacing rule Apr 11, 2020
@codecov
Copy link

codecov bot commented Apr 11, 2020

Codecov Report

Merging #1884 into master will increase coverage by 0.03%.
The diff coverage is 100.00%.

@@            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              
Flag Coverage Δ
#unittest 94.53% <100.00%> (+0.03%) ⬆️
Impacted Files Coverage Δ
...es/eslint-plugin/src/rules/object-curly-spacing.ts 100.00% <100.00%> (ø)

@bradzacher bradzacher added the enhancement: new base rule extension New base rule extension required to handle a TS specific case label Apr 12, 2020
@bradzacher bradzacher changed the title feat(eslint-plugin): implement object-curly-spacing rule feat(eslint-plugin): add rule object-curly-spacing Apr 12, 2020
@mpsijm
Copy link
Contributor

mpsijm commented May 6, 2020

@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)?

@bradzacher
Copy link
Member

Copy link
Member

@bradzacher bradzacher left a 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
It supports all options and features of the base rule.
It adds support for TypeScript's object types

Comment on lines +29 to +34
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}}'.",
},
Copy link
Member

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.

Suggested change
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,

Comment on lines +40 to +41
const spaced = context.options[0] === 'always',
sourceCode = context.getSourceCode();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

Suggested change
const spaced = context.options[0] === 'always',
sourceCode = context.getSourceCode();
const spaced = context.options[0] === 'always';
const sourceCode = context.getSourceCode();

Comment on lines +47 to +48
* @param {Object} option The option to exclude.
* @returns {boolean} Whether or not the property is excluded.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick

Suggested change
* @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.

Comment on lines +262 to +265
const first = sourceCode.getFirstToken(node)!,
last = getClosingBraceOfObject(node)!,
second = sourceCode.getTokenAfter(first, { includeComments: true })!,
penultimate = sourceCode.getTokenBefore(last, {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

Suggested change
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, {

@bradzacher bradzacher added the awaiting response Issues waiting for a reply from the OP or another party label May 17, 2020
@bradzacher bradzacher added stale PRs or Issues that are at risk of being or have been closed due to inactivity for a prolonged period and removed awaiting response Issues waiting for a reply from the OP or another party labels Sep 1, 2020
@bradzacher bradzacher closed this Sep 1, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement: new base rule extension New base rule extension required to handle a TS specific case stale PRs or Issues that are at risk of being or have been closed due to inactivity for a prolonged period
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[object-curly-spacing] One-line object types do not adhere to spacing rules
3 participants