TrySound / rollup-plugin-eslint

This plugin in migrated https://github.com/rollup/plugins/tree/master/packages/eslint
MIT License
61 stars 17 forks source link

working with aliases #23

Closed r4fx closed 6 years ago

r4fx commented 6 years ago

I trying to configure aliases to work with, as far my configuration inside .eslintrc.json works with eslint-import-resolver-alias, aliases are recognized inside files, errors like Unable to resolve path to module '~docs/foo.js' import/no-unresolved are disappears

But rollup-plugin-eslint does not see that aliases, is there any option to pass aliases to this plugin ?

r4fx commented 6 years ago

I found where the problem is. My eslintrc file with run configuration is placed in root directory, rollup package with rollup-plugin-eslint is in some levels down, so it can't see the configuration from the root.

So the solution is to place eslint run config in js file and then use path.resolve. Example use case:

eslintrc.js

const path = require('path');

module.exports = {
  'env': {},
  'extends': [
    'airbnb-base',
    'plugin:jest/recommended',
    'plugin:vue/recommended',
  ],
  'parserOptions': {
    'parser': 'babel-eslint',
  },
  'plugins': ['import', 'jest'],
  'settings': {
    'import/resolver': {
      'alias': {
        'map': [
          ['~@scss', path.resolve(__dirname, './packages/scss')],
          ['~@vue', path.resolve(__dirname, './packages/vue')],
          ['~@docs', path.resolve(__dirname, './packages/vue/docs')],
        ],
        'extensions': ['.js', '.vue', '.json', '.scss'],
      },
    },
  },
  'rules': {},
};