`prevent-abbreviations` - non-ASCII characters ignored in filenames
Kristinita opened this issue · comments
1. Summary
If I use eslint-plugin-html and check JavaScript inside HTML by using Unicorn, I get errors like this:
8:3 error The filename `Мiръ.html` should be named `Мindexръ.html`. A more descriptive name will do too unicorn/prevent-abbreviations
✖ 1 problem (1 error, 0 warnings)
2. MCVE
2.1. Files
.eslintrc.yml
:
extends:
- plugin:unicorn/all
plugins:
- html
- unicorn
Мiръ.html
(“мiръ” meaning “world”):
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
console.log("Kira Goddess!");
</script>
</head>
<body>
<p>Kira Goddess!</p>
</body>
</html>
2.2. Steps to reproduce
npm install --save-dev eslint eslint-plugin-html eslint-plugin-unicorn
npx eslint Мiръ.html
2.3. Behavior
2.3.1. Desired
No errors.
2.3.2. Current
8:3 error The filename `Мiръ.html` should be named `Мindexръ.html`. A more descriptive name will do too unicorn/prevent-abbreviations
✖ 1 problem (1 error, 0 warnings)
3. Possible implementations of the desired behavior
-
Make it possible to ignore HTML files via the
ignore
option or by introducing a new option such ascheckFilenamesExtensions
. For example:unicorn/prevent-abbreviations: - error - checkFilenamesExtensions: - ".js"
In this case, Unicorn will solely check names of files with the
.js
extension, but not with other extensions like.html
or.md
(if the user is using eslint-plugin-markdown). -
Make it possible to skip filenames like
Мiръ
containing non-ASCII symbols. For example, via the optioncheckNonASCIIFilenames: false
.
4. Not helped
-
I couldn’t find on Google and in this repository how I can solve the problem.
-
I can’t ignore all
.html
files with theignore
option. prevent-abbreviations documentation:When checking filenames, only the basename is tested. For example, with a file named
foo.e2e.js
, ignore:[/\.e2e$/]
would pass and ignore:[/\.e2e\.js/]
would fail.
5. Don’t offer
5.1. “Just use checkFilenames: false”
I need to ignore solely HTML files, I want to use checkFilenames
for JavaScript files. checkFilenames: false
also ignores checking of .js
files.
5.2. “Just ignore specific filenames”
Like this:
rules:
unicorn/prevent-abbreviations:
- error
- ignore:
- "Мiръ"
It would be nice if it were possible to ignore all .html
files instead of ignoring files individually. I solely use ASCII symbols for my JavaScript filenames, but I don’t think HTML filenames should have the same restrictions. I haven’t found reasons why I shouldn’t use filenames like Мiръ
for HTML files.
6. Environment
- Microsoft Windows 11 [Version 10.0.22621.3085]
- ESLint 8.57.0
- eslint-plugin-html 8.0.0
- eslint-plugin-unicorn 51.0.1
Thanks.
It looks like the bug is that it's not counting non-ASCII characters, so it sees "mi" instead of the full filename.
This is a bug and can be fixed.
If you want to disable specific rules on specific files, you can already do so via eslint overrides.