# eslint-plugin-import-naming

This ESLint plugin enforces consistent naming for default imports from specified packages. 
It ensures that the default import name matches the last segment of the imported package path, 
helping maintain clarity and consistency in your codebase.

## Rule: `match-package-default-import-name`

**Enforces that the default import name matches the module name for specified packages.**

### Why?

Mainly because of the `@sitevision/api` package, which has many modules that are imported with default imports.  
This rule helps ensure that the default import name matches the module name, improving readability and maintainability.  
But it works with any package, so it can be used to enforce consistent naming for default imports across your codebase.

## Usage

Add the plugin and rule to your ESLint configuration:

```js
// eslint.config.js (Flat config style)
import importNamingPlugin from './plugins/importNaming/index.js';

export default [
  {
    plugins: {
      'import-naming': importNamingPlugin,
    },
    rules: {
      'import-naming/match-package-default-import-name': [ 'warn', {
        packages: ['@sitevision/api', 'lodash', 'qs'], // Specify packages to enforce
      }],
    },
  },
];
```

## Rule Details

This rule checks default imports from the specified packages. The default import name must match the 
package name or last segment of the import path.

### Examples

#### Correct

```js
import PortletContextUtil from '@sitevision/api/server/PortletContextUtil'; // ✓ Default import name matches the last segment of the path
import qs from 'qs'; // ✓ Default import name matches the package name
import debounce from 'lodash/debounce'; // ✓ Default import name matches the last segment of the path (debounce)
```

#### Incorrect

```js
import portletContextUtil from '@sitevision/api/server/PortletContextUtil'; // ✗ Default import should be named PortletContextUtil
import myQs from 'qs'; // ✗ Default import should be named qs
import myDebounce from 'lodash/debounce'; // ✗ Default import should be named debounce
```

If the expected name is already used in the scope, a conflict warning is reported.

### Auto-fix

This rule is auto-fixable. ESLint can automatically rename the import and all its references to the correct name.

## Options

- `packages`: An array of package name prefixes to enforce (e.g., `['@sitevision/api', 'lodash']`).
