-
-
Notifications
You must be signed in to change notification settings - Fork 353
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 an internal ESLint rule prefer-negative-boolean-attribute
#1725
Merged
sindresorhus
merged 7 commits into
sindresorhus:main
from
fisker:prefer-negative-boolean-attribute
Feb 11, 2022
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7e75d03
Add a internal ESLint rule `prefer-negative-boolean-attribute`
fisker 5d12d63
Fix
fisker a8d45d2
Add package.json
fisker 9a73f83
Restore useless change
fisker 2ac3459
`npmpackagejsonlint`
fisker 3678b6e
Revert "Fix"
fisker 2704e64
Revert "Revert "Fix""
fisker File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
rules: { | ||
'prefer-negative-boolean-attribute': require('./prefer-negative-boolean-attribute.js'), | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"private": true, | ||
"name": "eslint-plugin-internal-rules", | ||
"description": "Internal rules", | ||
"license": "MIT" | ||
} |
44 changes: 44 additions & 0 deletions
44
scripts/internal-rules/prefer-negative-boolean-attribute.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
'use strict'; | ||
const path = require('path'); | ||
|
||
const messageId = path.basename(__filename, '.js'); | ||
|
||
const shouldReport = (string, value) => { | ||
const index = string.indexOf(`=${value}]`); | ||
|
||
if (index === -1) { | ||
return false; | ||
} | ||
|
||
return string[index - 1] !== '!'; | ||
}; | ||
|
||
module.exports = { | ||
create(context) { | ||
return { | ||
'TemplateElement, Literal'(node) { | ||
const string = node.value; | ||
if (typeof string !== 'string') { | ||
return; | ||
} | ||
|
||
for (const value of [true, false]) { | ||
if (shouldReport(string, value)) { | ||
context.report({ | ||
node, | ||
messageId, | ||
data: { | ||
preferred: String(!value), | ||
}, | ||
}); | ||
} | ||
} | ||
}, | ||
}; | ||
}, | ||
meta: { | ||
messages: { | ||
[messageId]: 'Prefer use `[…!={{preferred}}]` in esquery selector.', | ||
}, | ||
}, | ||
}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does eslint not offer a way to load a plugin from a file instead of a module?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This being a loooong story, and the reason is ridiculous, add a plugin path in config, ESLint can't get a plugin name to use...
eslint/eslint#3458
Unless you use the ESLint API, you can't add plugin in other way.
eslint-plugin-unicorn/test/integration/package.json
Line 8 in e8ab176
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could hack the module resolution like node core does but i guess it's even worse of a hack 😉.