-
-
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
Rule proposal: string-content
#327
Comments
I'm not sure how a lint rule would detect when it is appropriate to use one over the other. If you have a string such as That being said, there are similar potential rules with other shorthand strings:
I think the ellipsis would be the easiest to detect because exactly three periods in a row is pretty indicative of an ellipsis. But I'm wary of trying to challenge the content in strings -- I think linting is more suited for checking code syntax and style than English syntax and style. I suppose we could make this a generic string content scanner that took configured regex search / replace: "unicorn/string-content": ["warn", {
"patterns": [
{
"match": "'",
"suggest": "’",
"fix": false
},
{
"match": "..." ,
"suggest": "…",
"fix": true
}
]
}], Or some such. But I'm fairly skeptical. |
My fear is that it might cause some false positives; that’s why it should probably be limited to single apostrophes, exclusively to avoid escaping them. A generic “typography” rule would be difficult to manage since there are many cases in which punctuation is not part of user-visible text (e.g. selectors, queries) The replacer would be great too, as a generic rule |
To test the applicability of this rule in your projects, try looking for situations where grep "\\\'" -R . \
--exclude-dir node_modules \
--exclude-dir .git \
--include "*.js" \
--include "*.ts" \
--include "*.tsx" \
--exclude '*.min.*' |
I like the idea of a generic I think |
I would use the rule for important things: "unicorn/string-content": ["error", {
"patterns": [
{
"match": "unicorn",
"suggest": "🦄",
"fix": true
}
]
}] |
\'
→ ’
string-content
@issuehunt has funded $80.00 to this issue.
|
I'd like to work on this issue 👀 |
It's all yours :) |
Just make sure you read this thoroughly and have an understanding of AST and ESLint rules :) And add a lot of tests. It's better with too many than too few. |
@sindresorhus I have a problem on report message, if we treat match as {
match: 'https?:\\\/\\\/www\\\\.github\\\\.com',
suggest: 'github.com'
} How do we report?
Another problem, this rule original idea to fix [
{
match: '\\'',
suggest: '‘',
}
]
|
I would go with both 2 and 3. Default to 3, but allow overriding the message.
We could make the key be the match: {
'\\'': {
suggest: '‘'
}
} And allow setting it to {
'\\'': false
} |
Rewarding this issue is blocked by a dumb IssueHunt bug: https://spectrum.chat/issuehunt/general/error-when-accessing-an-issue-page~edd3be59-9228-472f-ae32-ce888e56bc1c?m=MTU4MzcyNjY3MjIxOQ== |
It's a dangerous rule xojs/xo#439 (comment) |
Good 👍
Not good 👎
Prior art: https://github.com/jmont/eslint-plugin-smart-quotes
I tried that one but it doesn't have a fixer and it has many false positives. Also strings could be CSS selectors so
[alt=""]
needs to stay as is.Originally posted by @sindresorhus in refined-github/refined-github#2167:
https://astexplorer.net/#/gist/3a67df351a57608ae38a6b55102376d6/c8425e326ddce75bf7242295c8818134ef2d2e16
IssueHunt Summary
Backers (Total: $80.00)
Submitted pull Requests
string-content
ruleBecome a backer now!
Or submit a pull request to get the deposits!
Tips
IssueHunt has been backed by the following sponsors. Become a sponsor
The text was updated successfully, but these errors were encountered: