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

Properly resolve base config #545

Merged
merged 1 commit into from
May 11, 2021
Merged
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
5 changes: 4 additions & 1 deletion lib/options-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ resolveFrom.silent = (moduleId, fromDirectory) => {
} catch { }
};

// TODO: Use `resolveModule(normalizePackageName(name), import.meta.url);` when moving to ESM then to `import.meta.resolve(normalizePackageName(name))` when supported
const resolveLocalConfig = name => resolveModule(normalizePackageName(name, 'eslint-config'), require.main.filename);
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't it be more correct to use path.resolve('..', __dirname) instead of require.main.filename?

I'm not sure how resolveModule works, but doesn't resolveModule(normalizePackageName(name), import.meta.url); also need to search from the parent directory of import.meta.url? Regarding the code comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

doesn't resolveModule(normalizePackageName(name), import.meta.url); also need to search from the parent directory of import.meta.url?

resolveModule just wraps require("module").createRequire(path).resolve(name) which is the same code that is recommended to be used in a related StackOverflow question.

Wouldn't it be more correct to use path.resolve('..', __dirname) instead of require.main.filename?

Better still, we could just use name => require.resolve(normalizePackageName(name)).


const nodeVersion = process && process.version;
const cacheLocation = findCacheDir({name: CACHE_DIR_NAME}) || path.join(os.homedir() || os.tmpdir(), '.xo-cache/');

Expand All @@ -62,7 +65,7 @@ const DEFAULT_CONFIG = {
globInputPaths: false,
baseConfig: {
extends: [
resolveFrom('eslint-config-xo'),
resolveLocalConfig('xo'),
path.join(__dirname, '../config/overrides.js'),
path.join(__dirname, '../config/plugins.js')
]
Expand Down