resolveOptionValue.mjs 810 B

123456789101112131415161718192021222324252627282930
  1. import getConfigForFile from '../getConfigForFile.mjs';
  2. /** @import {InternalApi, LinterOptions, Config} from 'stylelint' */
  3. /**
  4. * Get a value of the specified lint option or configuration.
  5. *
  6. * @template T
  7. * @param {Object} options
  8. * @param {InternalApi} options.stylelint
  9. * @param {keyof LinterOptions & keyof Config} options.name
  10. * @param {T} [options.default]
  11. * @returns {Promise<T>}
  12. */
  13. export default async function resolveOptionValue({
  14. stylelint,
  15. name,
  16. default: defaultValue = undefined,
  17. }) {
  18. const options = stylelint._options;
  19. const value = options[name] ?? options.config?.[name];
  20. if (value != null) {
  21. return /** @type {T} */ (value);
  22. }
  23. const configForFile = await getConfigForFile({ stylelint, failIfNoConfig: false });
  24. return configForFile?.config?.[name] ?? defaultValue;
  25. }