-
-
Notifications
You must be signed in to change notification settings - Fork 927
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# By Mike Allanson (6) and others # Via GitHub * master: Bump @types/lodash from 4.14.152 to 4.14.154 (#4817) Update CHANGELOG.md Fix with workaround a TypeError thrown for "html" (#4797) Update CHANGELOG.md Fix false positives for variables in font-family-no-missing-generic-family-keyword (#4806) Update CHANGELOG.md Add ignoreSelectors option to block-opening-brace-space-before (#4640) Update CHANGELOG.md Fix error message percentage/number precision for alpha-value-notation (#4802) Create new 'createPartialStylelintResult' module (#4815) Move function normalizeAllRuleSettings() out to a separate module (#4810)
- Loading branch information
Showing
17 changed files
with
256 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict'; | ||
|
||
let html; | ||
|
||
html.replace(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
'use strict'; | ||
|
||
const _ = require('lodash'); | ||
|
||
/** @typedef {import('stylelint').PostcssResult} PostcssResult */ | ||
/** @typedef {import('postcss').NodeSource} NodeSource */ | ||
/** @typedef {import('stylelint').StylelintResult} StylelintResult */ | ||
|
||
/** | ||
* @param {PostcssResult} [postcssResult] | ||
* @param {import('stylelint').StylelintCssSyntaxError} [cssSyntaxError] | ||
* @return {StylelintResult} | ||
*/ | ||
module.exports = function (postcssResult, cssSyntaxError) { | ||
/** @type {StylelintResult} */ | ||
let stylelintResult; | ||
/** @type {string | undefined} */ | ||
let source; | ||
|
||
if (postcssResult && postcssResult.root) { | ||
if (postcssResult.root.source) { | ||
source = postcssResult.root.source.input.file; | ||
|
||
if (!source && 'id' in postcssResult.root.source.input) { | ||
source = postcssResult.root.source.input.id; | ||
} | ||
} | ||
|
||
// Strip out deprecation warnings from the messages | ||
const deprecationMessages = _.remove(postcssResult.messages, { | ||
stylelintType: 'deprecation', | ||
}); | ||
const deprecations = deprecationMessages.map((deprecationMessage) => { | ||
return { | ||
text: deprecationMessage.text, | ||
reference: deprecationMessage.stylelintReference, | ||
}; | ||
}); | ||
|
||
// Also strip out invalid options | ||
const invalidOptionMessages = _.remove(postcssResult.messages, { | ||
stylelintType: 'invalidOption', | ||
}); | ||
const invalidOptionWarnings = invalidOptionMessages.map((invalidOptionMessage) => { | ||
return { | ||
text: invalidOptionMessage.text, | ||
}; | ||
}); | ||
|
||
const parseErrors = _.remove(postcssResult.messages, { | ||
stylelintType: 'parseError', | ||
}); | ||
|
||
// This defines the stylelint result object that formatters receive | ||
stylelintResult = { | ||
source, | ||
deprecations, | ||
invalidOptionWarnings, | ||
// TODO TYPES check which types are valid? postcss? stylelint? | ||
/* eslint-disable-next-line */ | ||
parseErrors: /** @type {any} */ (parseErrors), | ||
errored: postcssResult.stylelint.stylelintError, | ||
warnings: postcssResult.messages.map((message) => { | ||
return { | ||
line: message.line, | ||
column: message.column, | ||
rule: message.rule, | ||
severity: message.severity, | ||
text: message.text, | ||
}; | ||
}), | ||
ignored: postcssResult.stylelint.ignored, | ||
_postcssResult: postcssResult, | ||
}; | ||
} else if (cssSyntaxError) { | ||
if (cssSyntaxError.name !== 'CssSyntaxError') { | ||
throw cssSyntaxError; | ||
} | ||
|
||
stylelintResult = { | ||
source: cssSyntaxError.file || '<input css 1>', | ||
deprecations: [], | ||
invalidOptionWarnings: [], | ||
parseErrors: [], | ||
errored: true, | ||
warnings: [ | ||
{ | ||
line: cssSyntaxError.line, | ||
column: cssSyntaxError.column, | ||
rule: cssSyntaxError.name, | ||
severity: 'error', | ||
text: `${cssSyntaxError.reason} (${cssSyntaxError.name})`, | ||
}, | ||
], | ||
}; | ||
} else { | ||
throw new Error( | ||
'createPartialStylelintResult must be called with either postcssResult or CssSyntaxError', | ||
); | ||
} | ||
|
||
return stylelintResult; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
'use strict'; | ||
|
||
const _ = require('lodash'); | ||
const normalizeRuleSettings = require('./normalizeRuleSettings'); | ||
const rules = require('./rules'); | ||
|
||
/** @typedef {import('stylelint').StylelintConfigRules} StylelintConfigRules */ | ||
/** @typedef {import('stylelint').StylelintConfig} StylelintConfig */ | ||
|
||
/** | ||
* @param {StylelintConfig} config | ||
* @return {StylelintConfig} | ||
*/ | ||
function normalizeAllRuleSettings(config) { | ||
/** @type {StylelintConfigRules} */ | ||
const normalizedRules = {}; | ||
|
||
if (!config.rules) return config; | ||
|
||
Object.keys(config.rules).forEach((ruleName) => { | ||
const rawRuleSettings = _.get(config, ['rules', ruleName]); | ||
|
||
const rule = rules[ruleName] || _.get(config, ['pluginFunctions', ruleName]); | ||
|
||
if (!rule) { | ||
normalizedRules[ruleName] = []; | ||
} else { | ||
normalizedRules[ruleName] = normalizeRuleSettings( | ||
rawRuleSettings, | ||
ruleName, | ||
_.get(rule, 'primaryOptionArray'), | ||
); | ||
} | ||
}); | ||
|
||
config.rules = normalizedRules; | ||
|
||
return config; | ||
} | ||
|
||
module.exports = normalizeAllRuleSettings; |
Oops, something went wrong.