forked from sindresorhus/eslint-plugin-unicorn
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
720 additions
and
72 deletions.
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,78 @@ | ||
# Enforce better string content | ||
|
||
Enforce certain things about the contents of strings. For example, you can enforce using `’` instead of `'` to avoid escaping. Or you could block some words. The possibilities are endless. | ||
|
||
This rule is fixable. | ||
|
||
*It only reports one pattern per AST node at the time.* | ||
|
||
## Fail | ||
|
||
```js | ||
const foo = 'Someone\'s coming!'; | ||
``` | ||
|
||
## Pass | ||
|
||
```js | ||
const foo = 'Someone’s coming!'; | ||
``` | ||
|
||
## Options | ||
|
||
Type: `object` | ||
|
||
### patterns | ||
|
||
Type: `object` | ||
|
||
Extend [default patterns](#default-pattern). | ||
|
||
The example below: | ||
|
||
- Disables the default `'` → `’` replacement. | ||
- Adds a custom `unicorn` → `🦄` replacement. | ||
- Adds a custom `awesome` → `😎` replacement and a custom message. | ||
- Adds a custom `cool` → `😎` replacement, but disables auto fix. | ||
|
||
```json | ||
{ | ||
"unicorn/string-content": [ | ||
"error", | ||
{ | ||
"patterns": { | ||
"'": false, | ||
"unicorn": "🦄", | ||
"awesome": { | ||
"suggest": "😎", | ||
"message": "Please use `😎` instead of `awesome`." | ||
}, | ||
"cool": { | ||
"suggest": "😎", | ||
"fix": false | ||
} | ||
} | ||
} | ||
] | ||
} | ||
``` | ||
|
||
The key of `patterns` is treated as a regex, so you must escape special characters. | ||
|
||
For example, if you want to enforce `...` → `…`: | ||
|
||
```json | ||
{ | ||
"patterns": { | ||
"\\.\\.\\.": "…" | ||
} | ||
} | ||
``` | ||
|
||
## Default Pattern | ||
|
||
```json | ||
{ | ||
"'": "’" | ||
} | ||
``` |
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
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
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
Oops, something went wrong.