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

Add meta.fixable property to each rule #6181

Merged
merged 3 commits into from Jun 28, 2022

Conversation

ybiquitous
Copy link
Member

Which issue, if any, is this issue related to?

Closes #6099

Is there anything in the PR that needs further explanation?

This commit adds a new property meta.fixable to each rule.
Also, this fixes inaccurate docs about autofix.


I used the following script for jscodeshift to perform the task easily.
(though I needed to fix a few files manually)

/**
 * @type {import('jscodeshift').Transform}
 */
module.exports = function transform(fileInfo, api) {
	const j = api.jscodeshift;
	const root = j(fileInfo.source);

	root.findVariableDeclarators('meta').forEach((decl) => {
		if (root.find(j.Identifier, { name: 'fix' }).length > 0) {
			decl.node.init.properties.push(j.property('init', j.identifier('fixable'), j.literal(true)));
		}
	});

	return root.toSource();
};
$ npm i -D jscodeshift @types/jscodeshift
...

$ npx jscodeshift lib/rules/*/index.js
...

This commit add a new property `meta.fixable` to each rule.
Also, this fixes inaccurate docs about autofix.

---

I used the following script for [`jscodeshift`](https://github.com/facebook/jscodeshift) to perform the task easily.
(though I needed to fix a few files manually)

```js
/**
 * @type {import('jscodeshift').Transform}
 */
module.exports = function transform(fileInfo, api) {
	const j = api.jscodeshift;
	const root = j(fileInfo.source);

	root.findVariableDeclarators('meta').forEach((decl) => {
		if (root.find(j.Identifier, { name: 'fix' }).length > 0) {
			decl.node.init.properties.push(j.property('init', j.identifier('fixable'), j.literal(true)));
		}
	});

	return root.toSource();
};
```

```console
$ npm i -D jscodeshift @types/jscodeshift
...

$ npx jscodeshift lib/rules/*/index.js
...
```
});
}
describe('all rules', () => {
test.each(Object.entries(rules))('"%s" should have metadata', (_name, rule) => {
Copy link
Member Author

Choose a reason for hiding this comment

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

@ybiquitous ybiquitous marked this pull request as ready for review June 28, 2022 05:21
Copy link
Member

@jeddy3 jeddy3 left a comment

Choose a reason for hiding this comment

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

LGTM, thank you!

(Really nice using a codemod for this!)

@ybiquitous ybiquitous merged commit 2e3fa9a into main Jun 28, 2022
@ybiquitous ybiquitous deleted the issue-6099-add-fixable-metadata branch June 28, 2022 13:08
@ybiquitous
Copy link
Member Author

@jeddy3 Thank you. Changelog entry added:

  • Added: meta.fixable property to each rule (#6181).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Add meta.fixable property to each rule
2 participants