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

Support auto-lookup of .mjs and .cjs config files #2970

Merged
merged 1 commit into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/get-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const KNOWN_ROOT_PROPERTIES = new Set([
const SUPPORTED_OVERRIDE_KEYS = new Set(['files', 'rules']);
const SUPPORTED_FORMAT_PROPS = new Set(['name', 'outputFile']);

const CONFIG_FILE_NAME = '.template-lintrc.js';
const CONFIG_FILE_NAMES = ['.template-lintrc.js', '.template-lintrc.mjs', '.template-lintrc.cjs'];
const ALLOWED_ERROR_CODES = new Set([
// resolve package error codes
'MODULE_NOT_FOUND',
Expand Down Expand Up @@ -77,7 +77,7 @@ export async function resolveProjectConfig(workingDir, options) {
return {};
} else {
// look for our config file relative to the specified working directory
configPath = findUpSync(CONFIG_FILE_NAME, {
configPath = findUpSync(CONFIG_FILE_NAMES, {
cwd: workingDir,
});

Expand Down
32 changes: 32 additions & 0 deletions test/unit/get-config-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -970,4 +970,36 @@ describe('getRuleFromString', function () {
);
}
});

it('supports a `.template-lintrc.mjs` config file', async function () {
let project = await Project.defaultSetup();

project.write({
'.template-lintrc.mjs': `export default { extends: 'recommended' };`,
});

try {
const config = await resolveProjectConfig(project.baseDir, {});

expect(config).toEqual({ extends: 'recommended' });
} finally {
project.dispose();
}
});

it('supports a `.template-lintrc.cjs` config file', async function () {
let project = await Project.defaultSetup();

project.write({
'.template-lintrc.cjs': `module.exports = { extends: 'recommended' };`,
});

try {
const config = await resolveProjectConfig(project.baseDir, {});

expect(config).toEqual({ extends: 'recommended' });
} finally {
project.dispose();
}
});
});