resolveOptionValue.cjs 996 B

123456789101112131415161718192021222324252627282930313233343536
  1. // NOTICE: This file is generated by Rollup. To modify it,
  2. // please instead edit the ESM counterpart and rebuild with Rollup (npm run build).
  3. 'use strict';
  4. const getConfigForFile = require('../getConfigForFile.cjs');
  5. /** @import {InternalApi, LinterOptions, Config} from 'stylelint' */
  6. /**
  7. * Get a value of the specified lint option or configuration.
  8. *
  9. * @template T
  10. * @param {Object} options
  11. * @param {InternalApi} options.stylelint
  12. * @param {keyof LinterOptions & keyof Config} options.name
  13. * @param {T} [options.default]
  14. * @returns {Promise<T>}
  15. */
  16. async function resolveOptionValue({
  17. stylelint,
  18. name,
  19. default: defaultValue = undefined,
  20. }) {
  21. const options = stylelint._options;
  22. const value = options[name] ?? options.config?.[name];
  23. if (value != null) {
  24. return /** @type {T} */ (value);
  25. }
  26. const configForFile = await getConfigForFile({ stylelint, failIfNoConfig: false });
  27. return configForFile?.config?.[name] ?? defaultValue;
  28. }
  29. module.exports = resolveOptionValue;