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

Remove configOverrides option (#5522) #5530

Merged
merged 2 commits into from Sep 14, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 0 additions & 4 deletions docs/user-guide/usage/node-api.md
Expand Up @@ -18,10 +18,6 @@ A [configuration object](../configure.md).

stylelint does not bother looking for a `.stylelintrc` file if you use this option.

### `configOverrides`

A partial stylelint configuration object whose properties override the existing config object, whether stylelint loads the config via the `config` option or a `.stylelintrc` file.

### `code`

A string to lint.
Expand Down
37 changes: 0 additions & 37 deletions lib/__tests__/standalone.test.js
Expand Up @@ -305,43 +305,6 @@ describe('standalone with config locatable from process.cwd not file', () => {
});
});

describe('configOverrides', () => {
it('Setting `plugins` inside `**/__tests__/**` object should override the ones set in `config` object', () => {
return standalone({
code: '.bar {}',
configBasedir: __dirname,
config: {
plugins: [],
rules: {
'plugin/warn-about-bar': 'always',
},
},
configOverrides: {
plugins: ['./fixtures/plugin-warn-about-bar'],
},
}).then((linted) => {
expect(linted.results[0].warnings).toHaveLength(1);
expect(linted.results[0].warnings[0].text).toBe('found .bar (plugin/warn-about-bar)');
});
});

it('Setting `extends` inside `configOverrides` object should override the ones set in `config` object', () => {
return standalone({
code: '.bar {}',
configBasedir: __dirname,
config: {
extends: ['foo'],
},
configOverrides: {
extends: ['./fixtures/config-block-no-empty'],
},
}).then((linted) => {
expect(linted.results[0].warnings).toHaveLength(1);
expect(linted.results[0].warnings[0].text).toContain('block-no-empty');
});
});
});

describe('nonexistent codeFilename with loaded config', () => {
let actualCwd;

Expand Down
56 changes: 39 additions & 17 deletions lib/augmentConfig.js
Expand Up @@ -3,7 +3,6 @@
const configurationError = require('./utils/configurationError');
const getModulePath = require('./utils/getModulePath');
const globjoin = require('globjoin');
const merge = require('deepmerge');
ybiquitous marked this conversation as resolved.
Show resolved Hide resolved
const micromatch = require('micromatch');
const normalizeAllRuleSettings = require('./normalizeAllRuleSettings');
const path = require('path');
Expand All @@ -18,22 +17,8 @@ const slash = require('slash');
/** @typedef {import('stylelint').StylelintConfig} StylelintConfig */
/** @typedef {import('stylelint').CosmiconfigResult} CosmiconfigResult */

/** @type {import('deepmerge').Options} */
const MERGE_OPTIONS = {
arrayMerge: (target, source, options) => {
const destination = [...target];

source.forEach((item, index) => {
// @ts-expect-error -- The type definition is insufficient. See https://github.com/TehShrike/deepmerge/pull/231
destination[index] = options.cloneUnlessOtherwiseSpecified(item, options);
});

return destination;
},
};

/**
* - Merges config and configOverrides
* - Merges config and stylelint options
* - Makes all paths absolute
* - Merges extends
* @param {StylelintInternalApi} stylelint
Expand All @@ -48,7 +33,7 @@ function augmentConfigBasic(stylelint, config, configDir, allowOverrides, filePa
.then(() => {
if (!allowOverrides) return config;

return merge(config, stylelint._options.configOverrides || {}, MERGE_OPTIONS);
return addOptions(stylelint, config);
})
.then((augmentedConfig) => {
return extendConfig(stylelint, augmentedConfig, configDir);
Expand Down Expand Up @@ -452,4 +437,41 @@ function applyOverrides(fullConfig, configDir, filePath) {
return config;
}

/**
* Add options to the config
*
* @param {StylelintInternalApi} stylelint
* @param {StylelintConfig} config
*
* @returns {StylelintConfig}
*/
function addOptions(stylelint, config) {
const augmentedConfig = {
...config,
};

if (stylelint._options.ignoreDisables) {
augmentedConfig.ignoreDisables = stylelint._options.ignoreDisables;
}

if (stylelint._options.quiet) {
augmentedConfig.quiet = stylelint._options.quiet;
}

if (stylelint._options.reportNeedlessDisables) {
augmentedConfig.reportNeedlessDisables = stylelint._options.reportNeedlessDisables;
}

if (stylelint._options.reportInvalidScopeDisables) {
augmentedConfig.reportInvalidScopeDisables = stylelint._options.reportInvalidScopeDisables;
}

if (stylelint._options.reportDescriptionlessDisables) {
augmentedConfig.reportDescriptionlessDisables =
stylelint._options.reportDescriptionlessDisables;
}

return augmentedConfig;
}

module.exports = { augmentConfigExtended, augmentConfigFull, applyOverrides };
7 changes: 3 additions & 4 deletions lib/cli.js
Expand Up @@ -40,7 +40,7 @@ const EXIT_CODE_ERROR = 2;
* @property {boolean} [reportInvalidScopeDisables]
* @property {boolean} [reportDescriptionlessDisables]
* @property {number} [maxWarnings]
* @property {string | boolean} quiet
* @property {boolean} quiet
Copy link
Member Author

Choose a reason for hiding this comment

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

Don't know why it was string. Seems to me no different to other booleans.

* @property {string} [syntax]
* @property {string} [version]
* @property {boolean} [allowEmptyInput]
Expand All @@ -65,7 +65,7 @@ const EXIT_CODE_ERROR = 2;
* @property {string} [customSyntax]
* @property {string} [codeFilename]
* @property {string} [configBasedir]
* @property {{ quiet?: any }} configOverrides
* @property {boolean} [quiet]
* @property {any} [printConfig]
* @property {boolean} [fix]
* @property {boolean} [ignoreDisables]
Expand Down Expand Up @@ -349,11 +349,10 @@ module.exports = (argv) => {
/** @type {OptionBaseType} */
const optionsBase = {
formatter,
configOverrides: {},
};

if (cli.flags.quiet) {
optionsBase.configOverrides.quiet = cli.flags.quiet;
optionsBase.quiet = cli.flags.quiet;
}

if (cli.flags.syntax) {
Expand Down
18 changes: 0 additions & 18 deletions lib/createStylelint.js
Expand Up @@ -25,24 +25,6 @@ module.exports = function createStylelint(options = {}) {
/** @type {Partial<StylelintInternalApi>} */
const stylelint = { _options: options };

options.configOverrides = options.configOverrides || {};

if (options.ignoreDisables) {
options.configOverrides.ignoreDisables = options.ignoreDisables;
}

if (options.reportNeedlessDisables) {
options.configOverrides.reportNeedlessDisables = options.reportNeedlessDisables;
}

if (options.reportInvalidScopeDisables) {
options.configOverrides.reportInvalidScopeDisables = options.reportInvalidScopeDisables;
}

if (options.reportDescriptionlessDisables) {
options.configOverrides.reportDescriptionlessDisables = options.reportDescriptionlessDisables;
}

// @ts-ignore TODO TYPES found out which cosmiconfig types are valid
stylelint._extendExplorer = cosmiconfig(null, {
transform: augmentConfig.augmentConfigExtended.bind(
Expand Down
2 changes: 0 additions & 2 deletions lib/printConfig.js
Expand Up @@ -15,7 +15,6 @@ module.exports = function printConfig(options) {
const config = options.config;
const configBasedir = options.configBasedir;
const configFile = options.configFile;
const configOverrides = options.configOverrides;
const globbyOptions = options.globbyOptions;
const files = options.files;

Expand All @@ -37,7 +36,6 @@ module.exports = function printConfig(options) {
config,
configFile,
configBasedir,
configOverrides,
});

const cwd = (globbyOptions && globbyOptions.cwd) || process.cwd();
Expand Down
2 changes: 0 additions & 2 deletions lib/standalone.js
Expand Up @@ -39,7 +39,6 @@ module.exports = function (options) {
const config = options.config;
const configBasedir = options.configBasedir;
const configFile = options.configFile;
const configOverrides = options.configOverrides;
const customSyntax = options.customSyntax;
const globbyOptions = options.globbyOptions;
const files = options.files;
Expand Down Expand Up @@ -92,7 +91,6 @@ module.exports = function (options) {
config,
configFile,
configBasedir,
configOverrides,
ignoreDisables,
ignorePath: ignoreFilePath,
reportNeedlessDisables,
Expand Down
3 changes: 1 addition & 2 deletions types/stylelint/index.d.ts
Expand Up @@ -140,7 +140,6 @@ declare module 'stylelint' {
config?: StylelintConfig;
configFile?: string;
configBasedir?: string;
configOverrides?: StylelintConfig;
ignoreDisables?: boolean;
ignorePath?: string;
reportInvalidScopeDisables?: boolean;
Expand Down Expand Up @@ -212,7 +211,6 @@ declare module 'stylelint' {
config?: StylelintConfig;
configFile?: string;
configBasedir?: string;
configOverrides?: StylelintConfig;
printConfig?: string;
ignoreDisables?: boolean;
ignorePath?: string;
Expand All @@ -227,6 +225,7 @@ declare module 'stylelint' {
disableDefaultIgnores?: boolean;
fix?: boolean;
allowEmptyInput?: boolean;
quiet?: boolean;
};

export type StylelintCssSyntaxError = {
Expand Down