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

Docs: Give example for adding meta.name and meta.version to plugin config #18462

Open
1 task
MikeMcC399 opened this issue May 16, 2024 · 6 comments · May be fixed by #18530
Open
1 task

Docs: Give example for adding meta.name and meta.version to plugin config #18462

MikeMcC399 opened this issue May 16, 2024 · 6 comments · May be fixed by #18530
Assignees
Labels
documentation Relates to ESLint's documentation

Comments

@MikeMcC399
Copy link
Contributor

Docs page(s)

Create Plugins > Meta Data in Plugins

What documentation issue do you want to solve?

The text says:

The meta.name property should match the npm package name for your plugin and the meta.version property should match the npm package version for your plugin. The easiest way to accomplish this is by reading this information from your package.json.

If plugins are released using semantic-release, where the version is not updated in the repository, and is only changed in the npm registry, it may not be obvious how to achieve the synchronization of version data between the plugin's meta.version property and the published package.json's version property.

Also, providing an example of how to automate this step would help towards the name and version data being consistently published across all plugins, whether or not the committed package.json contains an up-to-date version property.

What do you think is the correct solution?

In https://github.com/eslint-community/eslint-plugin-eslint-comments/blob/main/configs.js there is an example which uses:

const { name, version } = require("./package.json")

const plugin = {
    meta: { name, version }
}

Possibly this could be added to the example in Create Plugins > Meta Data in Plugins and published (or the equivalent code using import instead of require).

Participation

  • I am willing to submit a pull request for this change.

Additional comments

I looked through the plugins which have been marked as v9 compatible on #18391 and most of them actually store their version in the committed package.json. Examples of ones which do not are:

@MikeMcC399 MikeMcC399 added the documentation Relates to ESLint's documentation label May 16, 2024
@nzakas
Copy link
Member

nzakas commented May 16, 2024

That sounds like a good idea. Can you submit a PR for that?

@MikeMcC399
Copy link
Contributor Author

@nzakas

That sounds like a good idea. Can you submit a PR for that?

I'm glad you agree that this would be a good idea!

When I came to writing something I realized that for ESLint v9 there are no recommendations about how to generate a plugin automatically or where to place a JavaScript config file. (PR eslint/generator-eslint#179 is still open.) For ESLint v8, Yeoman is recommended and this generates a lib/index.js file, i.e. in a sub-directory of the plugin's root directory.

Would you want to make some sort of best practice recommendation / default location for a config file? If there is none, then I would have to say that the import / require example assumes that the config file is in a certain location relative to the package.json file.

@MikeMcC399
Copy link
Contributor Author

Unfortunately I now realize that I only have a solution for CommonJS, not for ESM, so I would need to leave proposing a code example to somebody with more JavaScript Node.js skills than I currently posses.

Importing from JSON modules is experimental and has other restrictions.

@nzakas
Copy link
Member

nzakas commented May 17, 2024

You can actually use the same solution in both CommonJS and ESM: just read in package.json using fs and then run it through JSON.parse() to get the values.

@nzakas
Copy link
Member

nzakas commented May 30, 2024

@MikeMcC399 are you going to send a PR for this?

@MikeMcC399
Copy link
Contributor Author

@nzakas

are you going to send a PR for this?

If I had the skills to convert what you suggested into code then I would, but I don't. So regrettably, no I can't contribute a PR to implement this suggestion.

The box has to remain unticked:

  • I am willing to submit a pull request for this change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Relates to ESLint's documentation
Projects
Status: Implementing
Development

Successfully merging a pull request may close this issue.

2 participants