conarti / eslint-plugin-feature-sliced

Feature sliced design eslint plugin
30 stars 1 forks source link

Need to handle an error when parsing strange imports #12

Open yslpn opened 2 months ago

yslpn commented 2 months ago

Hello, thank you for plugin!

I have a problem with a library for internationalization that comes with a custom loader, and this loader requires a special import syntax. But in this case, many rules from the plugin simply fail when it comes to this file. Moreover, eslint-disable does not correct the situation with crashes.

Docs:

https://lingui.dev/ref/loader#usage

Example:

export async function dynamicActivate(locale: string) {
  const { messages } = await import(`@lingui/loader!./locales/${locale}/messages.po`);
  i18n.load(locale, messages);
  i18n.activate(locale);
}

Error:

Oops! Something went wrong! :(

ESLint: 8.57.0

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
Occurred while linting /Users/yslpn/Documents/Work/iva-ui/apps/aui/src/app/providers/I18nDynamicProvider.tsx:8
Rule: "@conarti/feature-sliced/layers-slices"
    at validateString (node:internal/validators:162:11)
    at Object.normalize (node:path:1131:5)
    at normalizePath (/Users/yslpn/Documents/Work/iva-ui/node_modules/@conarti/eslint-plugin-feature-sliced/dist/lib/path/normalize-path.js:12:10)
    at extractNodePath (/Users/yslpn/Documents/Work/iva-ui/node_modules/@conarti/eslint-plugin-feature-sliced/dist/lib/rule/extract-node-path.js:7:59)
    at isIgnoredTarget (/Users/yslpn/Documents/Work/iva-ui/node_modules/@conarti/eslint-plugin-feature-sliced/dist/lib/rule/is-ignored-target.js:8:68)
    at validateAndReport (/Users/yslpn/Documents/Work/iva-ui/node_modules/@conarti/eslint-plugin-feature-sliced/dist/rules/layers-slices/model/validate-and-report.js:34:63)
    at ImportExpression (/Users/yslpn/Documents/Work/iva-ui/node_modules/@conarti/eslint-plugin-feature-sliced/dist/rules/layers-slices/index.js:51:47)
    at ruleErrorHandler (/Users/yslpn/Documents/Work/iva-ui/node_modules/eslint/lib/linter/linter.js:1076:28)
    at /Users/yslpn/Documents/Work/iva-ui/node_modules/eslint/lib/linter/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)

As a temporary solution, I added the file to ignore at the eslint config level

ignorePatterns: ["src/app/providers/I18nDynamicProvider.tsx"]