UNPKG

968 BJavaScriptView Raw
1'use strict';
2
3const resolveConfig = require('./resolveConfig');
4const globby = require('globby');
5
6/** @typedef {import('stylelint').Config} StylelintConfig */
7
8/**
9 * @param {import('stylelint').LinterOptions} options
10 * @returns {Promise<StylelintConfig | null>}
11 */
12module.exports = async function printConfig({
13 cwd = process.cwd(),
14 code,
15 config,
16 configBasedir,
17 configFile,
18 globbyOptions,
19 files,
20}) {
21 const isCodeNotFile = code !== undefined;
22 const filePath = files && files[0];
23
24 if (!files || files.length !== 1 || !filePath || isCodeNotFile) {
25 return Promise.reject(
26 new Error('The --print-config option must be used with exactly one file path.'),
27 );
28 }
29
30 if (globby.hasMagic(filePath)) {
31 return Promise.reject(new Error('The --print-config option does not support globs.'));
32 }
33
34 return (
35 (await resolveConfig(filePath, {
36 cwd: (globbyOptions && globbyOptions.cwd) || cwd,
37 config,
38 configBasedir,
39 configFile,
40 })) || null
41 );
42};