Repository: sindresorhus/eslint-plugin-unicorn (JavaScript)

Issue:
`prevent-abbreviations` - non-ASCII characters ignored in filenames
### 1. Summary

If I use [**eslint-plugin-html**](https://github.com/BenoitZugmeyer/eslint-plugin-html) and check JavaScript inside HTML by using Unicorn, I get errors like this:

```text
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`:

```yaml
extends:
- plugin:unicorn/all

plugins:
- html
- unicorn

```

`Мiръ.html` ([**“мiръ” meaning “world”**](https://russianlife.com/the-russia-file/war-and-peace-7-fun-facts/)):

```html
<!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

```text
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

```text
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:

	```yaml
	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**](https://github.com/eslint/eslint-plugin-markdown)).

1. 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**](https://github.com/search?q=repo%253Asindresorhus%252Feslint-plugin-unicorn+prevent-abbreviations) how I can solve the problem.
1. I can’t ignore all `.html` files with the `ignore` option. [**prevent-abbreviations documentation**](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prevent-abbreviations.md#ignore):

	> 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`**](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prevent-abbreviations.md#checkfilenames) also ignores checking of `.js` files.

#### 5.2. “Just ignore specific filenames”

Like this:

```yaml
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]
1. ESLint 8.57.0
1. eslint-plugin-html 8.0.0
1. eslint-plugin-unicorn 51.0.1

Thanks.


Discussion:
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.
**Status: RESOLVED** :heavy_check_mark:

### Environment

1. Microsoft Windows 11 [Version 10.0.22621.3085]
1. Node.js v23.8.0
1. ESLint v9.21.0
1. eslint-plugin-html 8.1.2
1. unicorn 57.0.0

Thanks.

**Type: Addition** ➕

But interesting, that examples 1, 3 and 4 from [**the documentation of the setting `ignore`**](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/filename-case.md#ignore) are incorrect if we check them use ESLint and Unicorn:

```shell
G:\Kristinita>eslint eslint.config.mjs

G:\Kristinita\eslint.config.mjs
  170:7  error  `String.raw` should be used to avoid escaping `\`  unicorn/prefer-string-raw
  172:7  error  `String.raw` should be used to avoid escaping `\`  unicorn/prefer-string-raw
  173:7  error  Use the 'u' flag                                   require-unicode-regexp

```

Thanks.




Patch:
diff --git a/rules/prevent-abbreviations.js b/rules/prevent-abbreviations.js
index 5e5d382f66..661e0a5af9 100644
--- a/rules/prevent-abbreviations.js
+++ b/rules/prevent-abbreviations.js
@@ -116,7 +116,7 @@ const getNameReplacements = (name, options, limit = 3) => {
 	}
 
 	// Split words
-	const words = name.split(/(?=[^a-z])|(?<=[^A-Za-z])/).filter(Boolean);
+	const words = name.split(/(?=\P{Lowercase_Letter})|(?<=\P{Letter})/u).filter(Boolean);
 
 	let hasReplacements = false;
 	const combinations = words.map(word => {


Test patch:
diff --git a/test/prevent-abbreviations.mjs b/test/prevent-abbreviations.mjs
index 015f8abd62..6a81db822a 100644
--- a/test/prevent-abbreviations.mjs
+++ b/test/prevent-abbreviations.mjs
@@ -1931,6 +1931,10 @@ test({
 			code: 'foo();',
 			filename: 'err/http-error.js',
 		},
+		{
+			code: 'foo();',
+			filename: 'Мiръ.html',
+		},
 		// `ignore` option
 		{
 			code: outdent`