Permalink
Browse files

Lots of Flow work (#2163)

  • Loading branch information...
1 parent 98db725 commit fc3df1fc897f368914f199b4ee97e8f76fcbebf6 @davidtheclark davidtheclark committed with jeddy3 Dec 4, 2016
Showing with 284 additions and 255 deletions.
  1. +4 −0 decls/postcss.js
  2. +15 −4 lib/assignDisabledRanges.js
  3. +42 −23 lib/augmentConfig.js
  4. +5 −1 lib/createStylelintResult.js
  5. +4 −4 lib/getConfigForFile.js
  6. +7 −7 lib/getPostcssResult.js
  7. +4 −1 lib/isPathIgnored.js
  8. +10 −6 lib/lintSource.js
  9. +11 −8 lib/needlessDisables.js
  10. +5 −1 lib/normalizeRuleSettings.js
  11. +4 −1 lib/utils/beforeBlockString.js
  12. +3 −5 lib/utils/configurationError.js
  13. +5 −8 lib/utils/containsString.js
  14. +2 −4 lib/utils/declarationValueIndex.js
  15. +2 −4 lib/utils/findAnimationName.js
  16. +4 −4 lib/utils/findAtRuleContext.js
  17. +2 −1 lib/utils/findFontFamily.js
  18. +2 −4 lib/utils/findListStyleType.js
  19. +9 −6 lib/utils/functionArgumentsSearch.js
  20. +4 −1 lib/utils/getIsFileIgnored.js
  21. +1 −0 lib/utils/getModulePath.js
  22. +2 −4 lib/utils/getUnitFromValueNode.js
  23. +4 −1 lib/utils/hasBlock.js
  24. +4 −1 lib/utils/hasEmptyBlock.js
  25. +4 −5 lib/utils/hasEmptyLine.js
  26. +2 −1 lib/utils/hasInterpolation.js
  27. +2 −1 lib/utils/hasLessInterpolation.js
  28. +2 −4 lib/utils/hasPsvInterpolation.js
  29. +2 −4 lib/utils/hasScssInterpolation.js
  30. +6 −5 lib/utils/isAutoprefixable.js
  31. +2 −4 lib/utils/isCounterIncrementCustomIdentValue.js
  32. +2 −4 lib/utils/isCustomMediaQuery.js
  33. +2 −4 lib/utils/isCustomProperty.js
  34. +5 −7 lib/utils/isCustomPropertySet.js
  35. +2 −4 lib/utils/isCustomSelector.js
  36. +2 −4 lib/utils/isKeyframeRule.js
  37. +2 −4 lib/utils/isKeyframeSelector.js
  38. +1 −3 lib/utils/isNumbery.js
  39. +2 −4 lib/utils/isOnlyWhitespace.js
  40. +2 −1 lib/utils/isRangeContextMediaFeature.js
  41. +2 −1 lib/utils/isSingleLineString.js
  42. +1 −0 lib/utils/isStandardSyntaxAtRule.js
  43. +2 −4 lib/utils/isStandardSyntaxDeclaration.js
  44. +2 −4 lib/utils/isStandardSyntaxFunction.js
  45. +2 −4 lib/utils/isStandardSyntaxMediaFeature.js
  46. +2 −4 lib/utils/isStandardSyntaxMediaFeatureName.js
  47. +2 −4 lib/utils/isStandardSyntaxProperty.js
  48. +3 −5 lib/utils/isStandardSyntaxRule.js
  49. +2 −4 lib/utils/isStandardSyntaxSelector.js
  50. +2 −1 lib/utils/isStandardSyntaxTypeSelector.js
  51. +2 −4 lib/utils/isStandardSyntaxUrl.js
  52. +2 −4 lib/utils/isStandardSyntaxValue.js
  53. +2 −4 lib/utils/isValidFontSize.js
  54. +2 −4 lib/utils/isValidHex.js
  55. +2 −4 lib/utils/isVariable.js
  56. +2 −4 lib/utils/isWhitespace.js
  57. +5 −8 lib/utils/matchesStringOrRegExp.js
  58. +2 −5 lib/utils/nextNonCommentNode.js
  59. +1 −0 lib/utils/nodeContextLookup.js
  60. +6 −6 lib/utils/optionsMatches.js
  61. +7 −1 lib/utils/parseSelector.js
  62. +2 −4 lib/utils/rawNodeString.js
  63. +11 −11 lib/utils/report.js
  64. +5 −1 lib/utils/ruleMessages.js
  65. +2 −4 lib/utils/validateObjectWithStringArrayProps.js
  66. +5 −1 lib/utils/validateOptions.js
  67. +11 −1 lib/utils/whitespaceChecker.js
View
@@ -21,10 +21,14 @@ export type postcss$atRule = {
afterName: string,
},
type: string,
+ parent: Object,
+ nodes: Array<Object>
}
export type postcss$rule = {
raws: Object,
selector: string,
type: string,
+ parent: Object,
+ nodes: Array<Object>,
}
@@ -9,14 +9,18 @@ const disableLineCommand = COMMAND_PREFIX + "disable-line"
const disableNextLineCommand = COMMAND_PREFIX + "disable-next-line"
const ALL_RULES = "all"
-// Run it like a plugin ...
/*:: type disabledRangeObject = {
[ruleName: string]: Array<{
start: number,
end?: number,
}>
}*/
-module.exports = function (root/*: Object*/, result/*: Object*/) {
+
+// Run it like a plugin ...
+module.exports = function (
+ root/*: Object*/,
+ result/*: Object*/
+) {
result.stylelint = result.stylelint || {}
// Most of the functions below work via side effects mutating
@@ -41,7 +45,11 @@ module.exports = function (root/*: Object*/, result/*: Object*/) {
})
}
- function disableLine(line/*: number*/, ruleName/*: string*/, comment/*: postcss$comment*/) {
+ function disableLine(
+ line/*: number*/,
+ ruleName/*: string*/,
+ comment/*: postcss$comment*/
+ ) {
if (ruleIsDisabled(ALL_RULES)) {
throw comment.error("All rules have already been disabled", { plugin: "stylelint" })
}
@@ -132,7 +140,10 @@ module.exports = function (root/*: Object*/, result/*: Object*/) {
}
}
- function getCommandRules(command/*: string*/, fullText/*: string*/)/*: Array<string>*/ {
+ function getCommandRules(
+ command/*: string*/,
+ fullText/*: string*/
+ )/*: Array<string>*/ {
const rules = _.compact(fullText.slice(command.length).split(",")).map(r => r.trim())
if (_.isEmpty(rules)) {
return [ALL_RULES]
View
@@ -15,7 +15,11 @@ const FILE_NOT_FOUND_ERROR_CODE = "ENOENT"
// - Merges config and configOverrides
// - Makes all paths absolute
// - Merges extends
-function augmentConfigBasic(stylelint/*: stylelint$internalApi*/, config/*: stylelint$config*/, configDir/*: string*/)/*: Promise<stylelint$config>*/ {
+function augmentConfigBasic(
+ stylelint/*: stylelint$internalApi*/,
+ config/*: stylelint$config*/,
+ configDir/*: string*/
+)/*: Promise<stylelint$config>*/ {
return Promise.resolve().then(() => {
return _.merge(config, stylelint._options.configOverrides)
}).then(augmentedConfig => {
@@ -28,13 +32,13 @@ function augmentConfigBasic(stylelint/*: stylelint$internalApi*/, config/*: styl
// Extended configs need to be run through augmentConfigBasic
// but do not need the full treatment. Things like pluginFunctions
// will be resolved and added by the parent config.
-function augmentConfigExtended(stylelint/*: stylelint$internalApi*/, cosmiconfigResultArg/*: ?{
- config: stylelint$config,
- filepath: string,
- }*/)/*: Promise<?{
- config: stylelint$config,
- filepath: string,
- }>*/ {
+function augmentConfigExtended(
+ stylelint/*: stylelint$internalApi*/,
+ cosmiconfigResultArg/*: ?{
+ config: stylelint$config,
+ filepath: string,
+ }*/
+ )/*: Promise<?{ config: stylelint$config, filepath: string }>*/ {
const cosmiconfigResult = cosmiconfigResultArg // Lock in for Flow
if (!cosmiconfigResult) return Promise.resolve(null)
@@ -48,13 +52,13 @@ function augmentConfigExtended(stylelint/*: stylelint$internalApi*/, cosmiconfig
})
}
-function augmentConfigFull(stylelint/*: stylelint$internalApi*/, cosmiconfigResultArg/*: ?{
- config: stylelint$config,
- filepath: string,
- }*/)/*: Promise<?{
- config: stylelint$config,
- filepath: string
- }>*/ {
+function augmentConfigFull(
+ stylelint/*: stylelint$internalApi*/,
+ cosmiconfigResultArg/*: ?{
+ config: stylelint$config,
+ filepath: string,
+ }*/
+)/*: Promise<?{ config: stylelint$config, filepath: string }>*/ {
const cosmiconfigResult = cosmiconfigResultArg // Lock in for Flow
if (!cosmiconfigResult) return Promise.resolve(null)
@@ -85,7 +89,10 @@ function augmentConfigFull(stylelint/*: stylelint$internalApi*/, cosmiconfigResu
// Load a file ignore ignore patterns, if there is one;
// then add them to the config as an ignorePatterns property
-function addIgnorePatterns(stylelint/*: stylelint$internalApi*/, config/*: stylelint$config*/)/*: Promise<stylelint$config>*/ {
+function addIgnorePatterns(
+ stylelint/*: stylelint$internalApi*/,
+ config/*: stylelint$config*/
+)/*: Promise<stylelint$config>*/ {
const ignoreFilePath = stylelint._options.ignorePath || DEFAULT_IGNORE_FILENAME
const absoluteIgnoreFilePath = path.isAbsolute(ignoreFilePath) ? ignoreFilePath : path.resolve(process.cwd(), ignoreFilePath)
@@ -114,7 +121,10 @@ function addIgnorePatterns(stylelint/*: stylelint$internalApi*/, config/*: style
// - plugins
// - processors
// (extends handled elsewhere)
-function absolutizePaths(config/*: stylelint$config*/, configDir/*: string*/)/*: stylelint$config*/ {
+function absolutizePaths(
+ config/*: stylelint$config*/,
+ configDir/*: string*/
+)/*: stylelint$config*/ {
if (config.ignoreFiles) {
config.ignoreFiles = [].concat(config.ignoreFiles).map(glob => {
if (path.isAbsolute(glob.replace(/^!/, ""))) return glob
@@ -137,7 +147,10 @@ function absolutizePaths(config/*: stylelint$config*/, configDir/*: string*/)/*:
// Processors are absolutized in their own way because
// they can be and return a string or an array
-function absolutizeProcessors(processors/*: stylelint$configProcessors*/, configDir/*: string*/)/*: stylelint$configProcessors*/ {
+function absolutizeProcessors(
+ processors/*: stylelint$configProcessors*/,
+ configDir/*: string*/
+)/*: stylelint$configProcessors*/ {
const normalizedProcessors = Array.isArray(processors) ? processors : [processors]
return normalizedProcessors.map(item => {
@@ -149,7 +162,11 @@ function absolutizeProcessors(processors/*: stylelint$configProcessors*/, config
})
}
-function extendConfig(stylelint/*: stylelint$internalApi*/, config/*: stylelint$config*/, configDir/*: string*/)/*: Promise<stylelint$config>*/ {
+function extendConfig(
+ stylelint/*: stylelint$internalApi*/,
+ config/*: stylelint$config*/,
+ configDir/*: string*/
+)/*: Promise<stylelint$config>*/ {
if (config.extends === undefined) return Promise.resolve(config)
const normalizedExtends = Array.isArray(config.extends) ? config.extends : [config.extends]
@@ -168,10 +185,12 @@ function extendConfig(stylelint/*: stylelint$internalApi*/, config/*: stylelint$
})
}
-function loadExtendedConfig(stylelint/*: stylelint$internalApi*/, config/*: stylelint$config*/, configDir/*: string*/, extendLookup/*: string*/)/*: Promise<?{
- config: stylelint$config,
- filepath: string,
- }>*/ {
+function loadExtendedConfig(
+ stylelint/*: stylelint$internalApi*/,
+ config/*: stylelint$config*/,
+ configDir/*: string*/,
+ extendLookup/*: string*/
+)/*: Promise<?{ config: stylelint$config, filepath: string }>*/ {
const extendPath = getModulePath(configDir, extendLookup)
return stylelint._extendExplorer.load(null, extendPath)
}
@@ -2,7 +2,11 @@
"use strict"
const _ = require("lodash")
-module.exports = function (stylelint/*: stylelint$internalApi*/, postcssResult/*: Object*/, filePath/*:: ?: string*/)/*: Promise<stylelint$result>*/ {
+module.exports = function (
+ stylelint/*: stylelint$internalApi*/,
+ postcssResult/*: Object*/,
+ filePath/*:: ?: string*/
+)/*: Promise<stylelint$result>*/ {
const source = !postcssResult.root.source ? undefined : postcssResult.root.source.input.file || postcssResult.root.source.input.id
// Strip out deprecation warnings from the messages
@@ -4,10 +4,10 @@ const augmentConfigFull = require("./augmentConfig").augmentConfigFull
const configurationError = require("./utils/configurationError")
const path = require("path")
-module.exports = function (stylelint/*: stylelint$internalApi*/, searchPath/*:: ?: string*/)/*: Promise<?{
- config: stylelint$config,
- filepath: string
- }>*/ {
+module.exports = function (
+ stylelint/*: stylelint$internalApi*/,
+ searchPath/*:: ?: string*/
+)/*: Promise<?{ config: stylelint$config, filepath: string }>*/ {
searchPath = searchPath || process.cwd()
const optionsConfig = stylelint._options.config
@@ -11,13 +11,13 @@ const postcssProcessor = postcss()
module.exports = function (stylelint/*: stylelint$internalApi*/)/*: Promise<?Object>*/ {
const options/*: {
- code?: string,
- codeFilename?: string,
- filePath?: string,
- codeProcessors?: Array<Function>,
- syntax?: stylelint$syntaxes,
- customSyntax?: string
- }*/ = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}
+ code?: string,
+ codeFilename?: string,
+ filePath?: string,
+ codeProcessors?: Array<Function>,
+ syntax?: stylelint$syntaxes,
+ customSyntax?: string
+ }*/ = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}
const cached = stylelint._postcssResultCache.get(options.filePath)
if (cached) return Promise.resolve(cached)
@@ -9,7 +9,10 @@ const path = require("path")
// and will have incorporated any .stylelintignore file that was found
// into its ignorePatterns property. We then check the path
// against these.
-module.exports = function (stylelint/*: stylelint$internalApi*/, filePathArg/*:: ?: string*/)/*: Promise<boolean>*/ {
+module.exports = function (
+ stylelint/*: stylelint$internalApi*/,
+ filePathArg/*:: ?: string*/
+)/*: Promise<boolean>*/ {
const filePath = filePathArg // to please Flow
if (!filePath) {
return Promise.resolve(false)
View
@@ -9,11 +9,11 @@ const ruleDefinitions = require("./rules")
// or one that we create
module.exports = function (stylelint/*: stylelint$internalApi*/)/*: Promise<Object>*/ {
const options/*: {
- code?: string,
- codeFilename?: string,
- filePath?: string,
- existingPostcssResult?: Object,
- }*/ = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}
+ code?: string,
+ codeFilename?: string,
+ filePath?: string,
+ existingPostcssResult?: Object,
+ }*/ = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}
if (!options.filePath && options.code === undefined && !options.existingPostcssResult) {
return Promise.reject("You must provide filePath, code, or existingPostcssResult")
@@ -64,7 +64,11 @@ module.exports = function (stylelint/*: stylelint$internalApi*/)/*: Promise<Obje
})
}
-function lintPostcssResult(stylelint/*: stylelint$internalApi*/, postcssResult/*: Object*/, config/*: stylelint$config*/)/*: Promise<>*/ {
+function lintPostcssResult(
+ stylelint/*: stylelint$internalApi*/,
+ postcssResult/*: Object*/,
+ config/*: stylelint$config*/
+)/*: Promise<>*/ {
postcssResult.stylelint = postcssResult.stylelint || {}
postcssResult.stylelint.ruleSeverities = {}
postcssResult.stylelint.customMessages = {}
@@ -71,14 +71,17 @@ module.exports = function (results/*: Array<stylelint$result>*/)/*: stylelint$ne
return report
}
-function isWarningInRange(warning/*: {
- rule: string,
- line: number,
- }*/, range/*: {
- rules?: Array<string>,
- start: number,
- end?: number,
- }*/)/*: boolean*/ {
+function isWarningInRange(
+ warning/*: {
+ rule: string,
+ line: number
+ }*/,
+ range/*: {
+ rules?: Array<string>,
+ start: number,
+ end?: number,
+ }*/
+)/*: boolean*/ {
const rule = warning.rule,
line = warning.line
@@ -14,7 +14,11 @@ const _ = require("lodash")
// standard form: [primaryOption, secondaryOption]
// Except in the cases with null, a & b, in which case
// null is returned
-module.exports = function (rawSettings/*: stylelint$configRuleSettings*/, ruleName/*: string*/, primaryOptionArray/*:: ?: boolean*/)/*: ?Array<any | [any, Object]>*/ {
+module.exports = function (
+ rawSettings/*: stylelint$configRuleSettings*/,
+ ruleName/*: string*/,
+ primaryOptionArray/*:: ?: boolean*/
+)/*: ?Array<any | [any, Object]>*/ {
if (rawSettings === null) {
return null
}
@@ -1,6 +1,9 @@
/* @flow */
"use strict"
-module.exports = function (statement/*: Object*/, options/*:: ?: Object*/)/*: string*/ {
+module.exports = function (
+ statement/*: Object*/,
+ options/*:: ?: Object*/
+)/*: string*/ {
options = options || {}
let result = ""
@@ -1,13 +1,11 @@
+/* @flow */
"use strict"
/**
* Create configurationError from text and set CLI exit code
- *
- * @param {string} text
- * @return {Error} - The error, with text and exit code
*/
-module.exports = function (text) {
- const err = new Error(text)
+module.exports = function (text/*: string */)/* Object */ {
+ const err/*: Object*/ = new Error(text)
err.code = 78
return err
}
@@ -1,3 +1,4 @@
+/* @flow */
"use strict"
/**
@@ -6,15 +7,11 @@
*
* Any strings starting and ending with `/` are ignored. Use the
* matchesStringOrRegExp() util to match regexes.
- *
- * @param {string} input
- * @param {string|array} comparison
- * @return {boolean|object} `false` if no match is found.
- * If a match is found, returns an object with these properties:
- * - `match`: the `input` value that had a match
- * - `pattern`: the `comparison` pattern that had a match
*/
-module.exports = function containsString(input, comparison) {
+module.exports = function containsString(
+ input/*: string*/,
+ comparison/*: string | Array<string>*/
+)/*: false | { match: string, pattern: string }*/ {
if (!Array.isArray(comparison)) {
return testAgainstString(input, comparison)
}
@@ -1,12 +1,10 @@
+/* @flow */
"use strict"
/**
* Get the index of a declaration's value
- *
- * @param {Decl} decl
- * @return {int} The index
*/
-module.exports = function (decl) {
+module.exports = function (decl/*: Object*/)/*: number*/ {
const beforeColon = decl.toString().indexOf(":")
const afterColon = decl.raw("between").length - decl.raw("between").indexOf(":")
return beforeColon + afterColon
@@ -1,3 +1,4 @@
+/* @flow */
"use strict"
const keywordSets = require("../reference/keywordSets")
@@ -8,11 +9,8 @@ const postcssValueParser = require("postcss-value-parser")
/**
* Get the font-families within a `font` shorthand property value.
- *
- * @param {string} value
- * @return {object} Collection font-family nodes
*/
-module.exports = function findAnimationName(value) {
+module.exports = function findAnimationName(value/*: string*/)/*: Array<Object>*/ {
const animationNames = []
const valueNodes = postcssValueParser(value)
Oops, something went wrong.

0 comments on commit fc3df1f

Please sign in to comment.