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

Fix ESLint plugin load error #589

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/constants.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import path from 'node:path';
import createEsmUtils from 'esm-utils';

const MODULE_DIRECTORY = path.join(createEsmUtils(import.meta).dirname, '..');

const DEFAULT_IGNORES = [
'**/node_modules/**',
'**/bower_components/**',
Expand Down Expand Up @@ -133,6 +138,7 @@ const TSCONFIG_DEFAULTS = {
const CACHE_DIR_NAME = 'xo-linter';

export {
MODULE_DIRECTORY,
DEFAULT_IGNORES,
DEFAULT_EXTENSION,
TYPESCRIPT_EXTENSION,
Expand Down
10 changes: 7 additions & 3 deletions lib/options-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import murmur from 'imurmurhash';
import {Legacy} from '@eslint/eslintrc';
import createEsmUtils from 'esm-utils';
import {
MODULE_DIRECTORY,
DEFAULT_IGNORES,
DEFAULT_EXTENSION,
TYPESCRIPT_EXTENSION,
Expand All @@ -29,7 +30,7 @@ import {
CACHE_DIR_NAME,
} from './constants.js';

const {__dirname, json, require} = createEsmUtils(import.meta);
const {json, require} = createEsmUtils(import.meta);
const {normalizePackageName} = Legacy.naming;
const resolveModule = Legacy.ModuleResolver.resolve;

Expand All @@ -54,8 +55,8 @@ const DEFAULT_CONFIG = {
baseConfig: {
extends: [
resolveLocalConfig('xo'),
path.join(__dirname, '../config/overrides.cjs'),
path.join(__dirname, '../config/plugins.cjs'),
path.join(MODULE_DIRECTORY, 'config/overrides.cjs'),
path.join(MODULE_DIRECTORY, 'config/plugins.cjs'),
],
},
};
Expand Down Expand Up @@ -289,6 +290,9 @@ const buildESLintConfig = options => config => {
};
}

// Resolve plugins from XO root directory
config.resolvePluginsRelativeTo = MODULE_DIRECTORY;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this make it impossible for users to add ESLint plugins themselves?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested in eslint-plugin-unicorn, it can load eslint-plugin-eslint-plugin.


return {
...config,
...pick(options, ['cwd', 'filePath', 'fix']),
Expand Down