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

prevent-abbreviations - non-ASCII characters ignored in filenames #2292

Closed
Kristinita opened this issue Feb 25, 2024 · 1 comment · Fixed by #2308
Closed

prevent-abbreviations - non-ASCII characters ignored in filenames #2292

Kristinita opened this issue Feb 25, 2024 · 1 comment · Fixed by #2308

Comments

@Kristinita
Copy link

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

  1. Make it possible to ignore HTML files via the ignore option or by introducing a new option such as checkFilenamesExtensions. 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).

  2. Make it possible to skip filenames like Мiръ containing non-ASCII symbols. For example, via the option checkNonASCIIFilenames: false.

4. Not helped

  1. I couldn’t find on Google and in this repository how I can solve the problem.

  2. I can’t ignore all .html files with the ignore 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

  1. Microsoft Windows 11 [Version 10.0.22621.3085]
  2. ESLint 8.57.0
  3. eslint-plugin-html 8.0.0
  4. eslint-plugin-unicorn 51.0.1

Thanks.

@fregante
Copy link
Collaborator

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.

@fregante fregante changed the title bug/feature request(prevent-abbreviations): ignoring name checking for HTML files/files containing non-ASCII characters in names prevent-abbreviations - non-ASCII characters ignored in filenames Feb 29, 2024
MichaelBlm added a commit to MichaelBlm/eslint-plugin-unicorn that referenced this issue Apr 4, 2024
MichaelBlm added a commit to MichaelBlm/eslint-plugin-unicorn that referenced this issue Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants