3 const isWhitespace = require("../../utils/isWhitespace");
4 const report = require("../../utils/report");
5 const ruleMessages = require("../../utils/ruleMessages");
6 const styleSearch = require("style-search");
7 const validateOptions = require("../../utils/validateOptions");
9 const ruleName = "function-whitespace-after";
11 const messages = ruleMessages(ruleName, {
12 expected: 'Expected whitespace after ")"',
13 rejected: 'Unexpected whitespace after ")"'
16 const ACCEPTABLE_AFTER_CLOSING_PAREN = new Set([")", ",", "}", ":", undefined]);
18 const rule = function(expectation) {
19 return (root, result) => {
20 const validOptions = validateOptions(result, ruleName, {
22 possible: ["always", "never"]
28 root.walkDecls(decl => {
29 const declString = decl.toString();
35 functionArguments: "only"
38 checkClosingParen(declString, match.startIndex, decl);
43 function checkClosingParen(source, index, node) {
44 const nextChar = source[index + 1];
45 if (expectation === "always") {
46 // Allow for the next character to be a single empty space,
47 // another closing parenthesis, a comma, or the end of the value
48 if (nextChar === " ") {
51 if (nextChar === "\n") {
54 if (source.substr(index + 1, 2) === "\r\n") {
57 if (ACCEPTABLE_AFTER_CLOSING_PAREN.has(nextChar)) {
61 message: messages.expected,
67 } else if (expectation === "never") {
68 if (isWhitespace(nextChar)) {
70 message: messages.rejected,
82 rule.ruleName = ruleName;
83 rule.messages = messages;
84 module.exports = rule;