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

fixes #5: improve autofix #6

Merged
merged 1 commit into from
Feb 23, 2021
Merged

fixes #5: improve autofix #6

merged 1 commit into from
Feb 23, 2021

Conversation

mnahkies
Copy link
Contributor

For whatever reason node.start / node.end are not defined when running the rule in my project. This seems to cause the auto-fix to turn the code into garbage.

Instead, use the equivalent fixer.replaceText(node, content) that is recommended here: https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/prefer-replace-text.md

Unfortunately I couldn't replicate the issue in your test suite, but the existing test suite continues to pass, and the autofix now behaves correctly on my project.

Debug output: (console.log(node))

{
  type: 'Literal',
  raw: '...',
  value: '...',
  range: [ 843, 913 ],
  loc: { start: { line: 31, column: 15 }, end: { line: 31, column: 85 } },
  parent: {
    type: 'VariableDeclarator',
    id: {
      type: 'Identifier',
      name: 'test',
      range: [Array],
      loc: [Object],
      parent: [Circular]
    },
    init: [Circular],
    range: [ 836, 913 ],
    loc: { start: [Object], end: [Object] },
    parent: {
      type: 'VariableDeclaration',
      declarations: [Array],
      kind: 'const',
      range: [Array],
      loc: [Object],
      parent: [Object]
    }
  }
}
{
  type: 'JSXText',
  value: '...',
  raw: '...',
  range: [ 1670, 1787 ],
  loc: { start: { line: 54, column: 74 }, end: { line: 57, column: 10 } },
  parent: {
    type: 'JSXElement',
    openingElement: {
      type: 'JSXOpeningElement',
      typeParameters: undefined,
      selfClosing: false,
      name: [Object],
      attributes: [Array],
      range: [Array],
      loc: [Object],
      parent: [Circular]
    },
    closingElement: {
      type: 'JSXClosingElement',
      name: [Object],
      range: [Array],
      loc: [Object],
      parent: [Circular]
    },
    children: [ [Circular] ],
    range: [ 1606, 1794 ],
    loc: { start: [Object], end: [Object] },
    parent: {
      type: 'JSXElement',
      openingElement: [Object],
      closingElement: [Object],
      children: [Array],
      range: [Array],
      loc: [Object],
      parent: [Object]
    }
  }
}

- in some project setups node.start / node.end is undefined,
  and results in the auto fix outputing invalid code
@seleb seleb merged commit 147d090 into seleb:master Feb 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants