eslint-plugin-jsonc icon indicating copy to clipboard operation
eslint-plugin-jsonc copied to clipboard

Resolve other plugins as siblings to this plugin

Open onlywei opened this issue 1 year ago • 2 comments

Why do I want this? I have a monorepo with the current file structure:

apps/
-  app1/
  -  package.json
   .............
-  app127/
  -  package.json
packages/
-  package1/
  -  package.json
   ............
-  package453/
  -  package.json
repotools/
-  central-linter/
  -  package.json
.eslintrc.json
.eslintignore

I want to install eslint and all of its configs and plugins into the repotools/central-linter/node_modules. I do not want to install a separate copy of eslint and its plugins in each app/package. Also note that there is no package.json file at the root of the repo because I have lots of issues with npm workspaces.

I also want to keep the .eslintrc.json and .eslintignore files at the root of the monorepo for better IDE integration.

I am able to accomplish all of this except for this eslint-plugin-jsonc since this plugin keeps trying to load plugins relative to the root of the monorepo, rather than the resolvePluginsRelativeTo that I passed to my central linter.

This PR should modify the behavior of eslint-plugin-jsonc to always resolve plugins relative to itself.

P.S. I cannot upgrade to ESLint v9 yet because nx and eslint-plugin-react does not support ESLint v9 yet.

onlywei avatar May 13 '24 15:05 onlywei

🦋 Changeset detected

Latest commit: b6a1cb48d1ba718f246a6f4f0f6d2d4c4b4f8913

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
eslint-plugin-jsonc Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

changeset-bot[bot] avatar May 13 '24 15:05 changeset-bot[bot]

@ota-meshi Whenever you get a chance, could you please take a look at this PR? Thank you!

onlywei avatar May 22 '24 19:05 onlywei

Hmm. I'm not sure if this PR change will work in anyone's environment. Can you please explain that it's not just your environment that works?

ota-meshi avatar May 24 '24 07:05 ota-meshi

Hmm. I'm not sure if this PR change will work in anyone's environment. Can you please explain that it's not just your environment that works?

@ota-meshi My thinking is this: two scenarios:

Scenario One: with --resolve-plugins-relative-to

In this scenario, the folder structure is as follows:

some/other/path/
  node_modules/
    eslint-plugin-prettier/
    eslint-plugin-jsonc/
      dist/
        utils/
          get-auto-jsonc-rules-config/
            index.ts
.eslintrc.cjs

Eslint is executed on the CLI using:

eslint --resolve-plugins-relative-to=some/other/path/ .

We want to resolve the eslint-plugin-prettier that is a sibling of eslint-plugin-jsonc. From dist/utils/get-auto-jsonc-rules-config/, we need to navigate up five directories in order to be at another-path/. Once we are there, require('eslint-plugin-prettier') should work and find the correct path.

Scenario One: WITHOUT --resolve-plugins-relative-to

In this scenario, which is how most people use eslint, the folder structure is as follows:

node_modules/
  eslint-plugin-prettier/
  eslint-plugin-jsonc/
    dist/
      utils/
        get-auto-jsonc-rules-config/
          index.ts
.eslintrc.cjs

Eslint is executed on the CLI using:

eslint .

From dist/utils/get-auto-jsonc-rules-config/, if we navigate up five directories, we will be at the root of this folder structure. The behavior here should be the exact same as if I had not submitted this PR at all.

Therefore, I believe this PR should work in both scenarios.

onlywei avatar May 24 '24 18:05 onlywei

Thank you for the explanation! I think that explanation makes sense!

ota-meshi avatar May 25 '24 00:05 ota-meshi