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

Codemod for v8 -> v9 rule API changes #25

Open
nzakas opened this issue May 15, 2024 · 4 comments · May be fixed by #29
Open

Codemod for v8 -> v9 rule API changes #25

nzakas opened this issue May 15, 2024 · 4 comments · May be fixed by #29

Comments

@nzakas
Copy link
Member

nzakas commented May 15, 2024

We should create a codemod that applies most of the changes mentioned in the blog post about changes to the rule API. Primarily changing:

  • context.getScope()
  • context.markVariableAsUsed()
  • context.getAncestors()
  • context.getDeclaredVariables()

For each of these, we should be creating backwards-compatible code such as:

const sourceCode = context.sourceCode ?? context.getSourceCode();
const cwd = context.cwd ?? context.getCwd();
const filename = context.filename ?? context.getFilename();
const physicalFilename = context.physicalFilename ?? context.getPhysicalFilename();

We should also update references to the methods listed in this section

If we find a reference to CodePath#currentSegments, then the best thing to do is output a warning stating that it can't be fixed automatically and point to this section.

(It probably can be fixed automatically but would be pretty complicated. If we get enough requests then we can revisit.)

@nzakas nzakas self-assigned this May 15, 2024
@nzakas nzakas removed their assignment May 15, 2024
@mdjermanovic
Copy link
Member

I'm wondering if we need this project anymore, because eslint + eslint-plugin-eslint-plugin could be able to do the same.

eslint-community/eslint-plugin-eslint-plugin#398

@nzakas
Copy link
Member Author

nzakas commented May 16, 2024

Maybe, but creating a dependency on ESLint in order to fix plugins that aren't working in ESLint might cause issues. I think updating this tool to have something standalone is beneficial at least in the near term.

@mdjermanovic
Copy link
Member

eslint and eslint-plugin-eslint-plugin would only be dev dependencies. I believe most if not all plugins already have eslint as a dev dependency, and a lot of plugins already use eslint-plugin-eslint-plugin (and eslint plugins should generally be using eslint-plugin-eslint-plugin anyway). In any case, they could use them as a one-time tool to fix the code and then uninstall them.

But okay, I'm not opposed to updating this tool as well.

@snitin315 snitin315 self-assigned this May 21, 2024
@snitin315
Copy link
Contributor

We should also update references to the methods listed in this section

How should we handle context.getComments() in the codemod? Since SourceCode.getComments() was removed in v9. Should we just log a warning and link to docs?
Screenshot 2024-05-21 at 9 27 56 PM

@snitin315 snitin315 linked a pull request May 22, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Implementing
Development

Successfully merging a pull request may close this issue.

3 participants