Skip to content

Commit

Permalink
Remove configOverrides option (#5522) (#5530)
Browse files Browse the repository at this point in the history
* Remove `configOverrides` option (#5522)

* Move deepmerge to devDependencies
  • Loading branch information
hudochenkov committed Sep 14, 2021
1 parent 5d7695a commit 56a4a76
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 89 deletions.
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');
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
* @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
6 changes: 4 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -111,7 +111,6 @@
"chalk": "^4.1.2",
"cosmiconfig": "^7.0.1",
"debug": "^4.3.2",
"deepmerge": "^4.2.2",
"execall": "^2.0.0",
"fast-glob": "^3.2.7",
"fastest-levenshtein": "^1.0.12",
Expand Down Expand Up @@ -167,6 +166,7 @@
"@types/write-file-atomic": "^3.0.2",
"benchmark": "^2.1.4",
"common-tags": "^1.8.0",
"deepmerge": "^4.2.2",
"eslint": "^7.32.0",
"eslint-config-stylelint": "^13.1.1",
"got": "^11.8.2",
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

0 comments on commit 56a4a76

Please sign in to comment.