github-pages-deploy-action/node_modules/eslint-plugin-jsdoc/dist/rules/checkExamples.js.map
2020-03-31 08:40:00 -04:00

1 line
20 KiB
Plaintext

{"version":3,"sources":["../../src/rules/checkExamples.js"],"names":["zeroBasedLineIndexAdjust","likelyNestedJSDocIndentSpace","preTagSpaceLength","firstLinePrefixLength","hasCaptionRegex","escapeStringRegexp","str","replace","countChars","ch","match","RegExp","length","getRegexFromString","regexString","flags","regex","uniqueFlags","Set","join","report","utils","context","globalState","tagName","getPreferredTagName","hasTag","has","set","Map","matchingFileNameMap","get","options","exampleCodeRegex","rejectExampleCodeRegex","noDefaultExampleRules","checkEslintrc","matchingFileName","filename","paddedIndent","baseConfig","configFile","allowInlineConfig","reportUnusedDisableDirectives","captionRequired","defaultFileName","jsFileName","getFilename","includes","rulePaths","rules","undefined","forEachPreferredTag","tag","targetTagName","source","description","trim","test","sources","nonJSPrefacingCols","nonJSPrefacingLines","startingIndex","lastStringCount","exampleCode","lastIndex","exec","index","n0","n1","preMatch","slice","preMatchLines","colDelta","lastIndexOf","nonJSPreface","nonJSPrefaceLineCount","idx","indexOf","charsInLastLine","string","push","global","checkRules","cliConfig","useEslintrc","cliConfigStr","JSON","stringify","src","fileNameMapKey","file","cliFile","cli","CLIEngine","config","getConfigForFile","executeOnText","results","messages","codeStartLine","line","codeStartCol","forEach","message","column","severity","ruleId","startLine","startCol","iterateAllJsdocs","meta","schema","additionalProperties","properties","default","type","noTrim"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;;;;;;;;;;;;;;;;;AAEA,MAAMA,wBAAwB,GAAG,CAAC,CAAlC;AACA,MAAMC,4BAA4B,GAAG,CAArC;AACA,MAAMC,iBAAiB,GAAG,CAA1B,C,CAEA;;AACA,MAAMC,qBAAqB,GAAGD,iBAA9B;AAEA,MAAME,eAAe,GAAG,gCAAxB;;AAEA,MAAMC,kBAAkB,GAAIC,GAAD,IAAS;AAClC,SAAOA,GAAG,CAACC,OAAJ,CAAY,sBAAZ,EAAoC,MAApC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IAAI,EAAE;AAFW,SADT;AAKV5E,QAAAA,UAAU,EAAE;AACV4E,UAAAA,IAAI,EAAE;AADI,SALF;AAQVxE,QAAAA,eAAe,EAAE;AACfuE,UAAAA,OAAO,EAAE,KADM;AAEfC,UAAAA,IAAI,EAAE;AAFS,SARP;AAYVhF,QAAAA,aAAa,EAAE;AACb+E,UAAAA,OAAO,EAAE,IADI;AAEbC,UAAAA,IAAI,EAAE;AAFO,SAZL;AAgBV3E,QAAAA,UAAU,EAAE;AACV2E,UAAAA,IAAI,EAAE;AADI,SAhBF;AAmBVnF,QAAAA,gBAAgB,EAAE;AAChBmF,UAAAA,IAAI,EAAE;AADU,SAnBR;AAsBV/E,QAAAA,gBAAgB,EAAE;AAChB+E,UAAAA,IAAI,EAAE;AADU,SAtBR;AAyBVjF,QAAAA,qBAAqB,EAAE;AACrBgF,UAAAA,OAAO,EAAE,KADY;AAErBC,UAAAA,IAAI,EAAE;AAFe,SAzBb;AA6BV7E,QAAAA,YAAY,EAAE;AACZ4E,UAAAA,OAAO,EAAE,CADG;AAEZC,UAAAA,IAAI,EAAE;AAFM,SA7BJ;AAiCVlF,QAAAA,sBAAsB,EAAE;AACtBkF,UAAAA,IAAI,EAAE;AADgB,SAjCd;AAoCVzE,QAAAA,6BAA6B,EAAE;AAC7BwE,UAAAA,OAAO,EAAE,IADoB;AAE7BC,UAAAA,IAAI,EAAE;AAFuB;AApCrB,OAFd;AA2CEA,MAAAA,IAAI,EAAE;AA3CR,KADM,CADJ;AAgDJA,IAAAA,IAAI,EAAE;AAhDF,GAFL;AAoDDC,EAAAA,MAAM,EAAE;AApDP,CA3PY,C","sourcesContent":["import {CLIEngine} from 'eslint';\nimport iterateJsdoc from '../iterateJsdoc';\nimport warnRemovedSettings from '../warnRemovedSettings';\n\nconst zeroBasedLineIndexAdjust = -1;\nconst likelyNestedJSDocIndentSpace = 1;\nconst preTagSpaceLength = 1;\n\n// If a space is present, we should ignore it\nconst firstLinePrefixLength = preTagSpaceLength;\n\nconst hasCaptionRegex = /^\\s*<caption>(.*?)<\\/caption>/u;\n\nconst escapeStringRegexp = (str) => {\n return str.replace(/[.*+?^${}()|[\\]\\\\]/gu, '\\\\$&');\n};\nconst countChars = (str, ch) => {\n return (str.match(new RegExp(escapeStringRegexp(ch), 'gu')) || []).length;\n};\n\nconst getRegexFromString = (regexString) => {\n const match = regexString.match(/^\\/(.*)\\/([gimyus]*)$/u);\n let flags = 'u';\n let regex = regexString;\n if (match) {\n [, regex, flags] = match;\n if (!flags) {\n flags = 'u';\n }\n const uniqueFlags = [...new Set(flags)];\n flags = uniqueFlags.join('');\n }\n\n return new RegExp(regex, flags);\n};\n\nexport default iterateJsdoc(({\n report,\n utils,\n context,\n globalState,\n}) => {\n warnRemovedSettings(context, 'check-examples');\n const tagName = utils.getPreferredTagName({tagName: 'example'});\n if (!utils.hasTag(tagName)) {\n return;\n }\n\n if (!globalState.has('checkExamples-matchingFileName')) {\n globalState.set('checkExamples-matchingFileName', new Map());\n }\n const matchingFileNameMap = globalState.get('checkExamples-matchingFileName');\n\n const options = context.options[0] || {};\n let {\n exampleCodeRegex = null,\n rejectExampleCodeRegex = null,\n } = options;\n const {\n noDefaultExampleRules = false,\n checkEslintrc = true,\n matchingFileName: filename = null,\n paddedIndent = 0,\n baseConfig = {},\n configFile,\n allowInlineConfig = true,\n reportUnusedDisableDirectives = true,\n captionRequired = false,\n } = options;\n\n let defaultFileName;\n if (!filename) {\n const jsFileName = context.getFilename();\n if (typeof jsFileName === 'string' && jsFileName.includes('.')) {\n defaultFileName = jsFileName.replace(/\\..*?$/, '.md');\n } else {\n defaultFileName = 'dummy.md';\n }\n }\n\n // Make this configurable?\n const rulePaths = [];\n\n const rules = noDefaultExampleRules ? undefined : {\n // \"always\" newline rule at end unlikely in sample code\n 'eol-last': 0,\n\n // Wouldn't generally expect example paths to resolve relative to JS file\n 'import/no-unresolved': 0,\n\n // Snippets likely too short to always include import/export info\n 'import/unambiguous': 0,\n\n // Unlikely to have inadvertent debugging within examples\n 'no-console': 0,\n\n // Often wish to start `@example` code after newline; also may use\n // empty lines for spacing\n 'no-multiple-empty-lines': 0,\n\n // Many variables in examples will be `undefined`\n 'no-undef': 0,\n\n // Common to define variables for clarity without always using them\n 'no-unused-vars': 0,\n\n // See import/no-unresolved\n 'node/no-missing-import': 0,\n 'node/no-missing-require': 0,\n\n // Can generally look nicer to pad a little even if code imposes more stringency\n 'padded-blocks': 0,\n };\n\n if (exampleCodeRegex) {\n exampleCodeRegex = getRegexFromString(exampleCodeRegex);\n }\n if (rejectExampleCodeRegex) {\n rejectExampleCodeRegex = getRegexFromString(rejectExampleCodeRegex);\n }\n\n utils.forEachPreferredTag('example', (tag, targetTagName) => {\n let source = tag.description;\n const match = source.match(hasCaptionRegex);\n\n if (captionRequired && (!match || !match[1].trim())) {\n report('Caption is expected for examples.', null, tag);\n }\n\n // If we allow newlines in hasCaptionRegex, we should add to line count\n source = source.replace(hasCaptionRegex, '');\n\n if (exampleCodeRegex && !exampleCodeRegex.test(source) ||\n rejectExampleCodeRegex && rejectExampleCodeRegex.test(source)\n ) {\n return;\n }\n\n const sources = [];\n if (exampleCodeRegex) {\n let nonJSPrefacingCols = 0;\n let nonJSPrefacingLines = 0;\n\n let startingIndex = 0;\n let lastStringCount = 0;\n\n let exampleCode;\n exampleCodeRegex.lastIndex = 0;\n while ((exampleCode = exampleCodeRegex.exec(source)) !== null) {\n const {index, 0: n0, 1: n1} = exampleCode;\n\n // Count anything preceding user regex match (can affect line numbering)\n const preMatch = source.slice(startingIndex, index);\n\n const preMatchLines = countChars(preMatch, '\\n');\n\n const colDelta = preMatchLines ?\n preMatch.slice(preMatch.lastIndexOf('\\n') + 1).length :\n preMatch.length;\n\n let nonJSPreface;\n let nonJSPrefaceLineCount;\n if (n1) {\n const idx = n0.indexOf(n1);\n nonJSPreface = n0.slice(0, idx);\n nonJSPrefaceLineCount = countChars(nonJSPreface, '\\n');\n } else {\n nonJSPreface = '';\n nonJSPrefaceLineCount = 0;\n }\n\n nonJSPrefacingLines += lastStringCount + preMatchLines + nonJSPrefaceLineCount;\n\n // Ignore `preMatch` delta if newlines here\n if (nonJSPrefaceLineCount) {\n const charsInLastLine = nonJSPreface.slice(nonJSPreface.lastIndexOf('\\n') + 1).length;\n\n nonJSPrefacingCols += charsInLastLine;\n } else {\n nonJSPrefacingCols += colDelta + nonJSPreface.length;\n }\n\n const string = n1 || n0;\n sources.push({\n nonJSPrefacingCols,\n nonJSPrefacingLines,\n string,\n });\n startingIndex = exampleCodeRegex.lastIndex;\n lastStringCount = countChars(string, '\\n');\n if (!exampleCodeRegex.global) {\n break;\n }\n }\n } else {\n sources.push({\n nonJSPrefacingCols: 0,\n nonJSPrefacingLines: 0,\n string: source,\n });\n }\n\n // Todo: Make fixable\n // Todo: Fix whitespace indent\n const checkRules = function ({\n nonJSPrefacingCols,\n nonJSPrefacingLines,\n string,\n }) {\n const cliConfig = {\n allowInlineConfig,\n baseConfig,\n configFile,\n reportUnusedDisableDirectives,\n rulePaths,\n rules,\n useEslintrc: checkEslintrc,\n };\n const cliConfigStr = JSON.stringify(cliConfig);\n\n const src = paddedIndent ?\n string.replace(new RegExp(`(^|\\n) {${paddedIndent}}(?!$)`, 'gu'), '\\n') :\n string;\n\n // Programmatic ESLint API: https://eslint.org/docs/developer-guide/nodejs-api\n const fileNameMapKey = filename ?\n 'a' + cliConfigStr + filename :\n 'b' + cliConfigStr + defaultFileName;\n const file = filename || defaultFileName;\n let cliFile;\n if (matchingFileNameMap.has(fileNameMapKey)) {\n cliFile = matchingFileNameMap.get(fileNameMapKey);\n } else {\n const cli = new CLIEngine(cliConfig);\n let config;\n if (filename || checkEslintrc) {\n config = cli.getConfigForFile(file);\n }\n\n // We need a new instance to ensure that the rules that may only\n // be available to `file` (if it has its own `.eslintrc`),\n // will be defined.\n cliFile = new CLIEngine({\n allowInlineConfig,\n baseConfig: {\n ...baseConfig,\n ...config,\n },\n configFile,\n reportUnusedDisableDirectives,\n rulePaths,\n rules,\n useEslintrc: false,\n });\n matchingFileNameMap.set(fileNameMapKey, cliFile);\n }\n\n const {results: [{messages}]} =\n cliFile.executeOnText(src);\n\n // NOTE: `tag.line` can be 0 if of form `/** @tag ... */`\n const codeStartLine = tag.line + nonJSPrefacingLines;\n const codeStartCol = likelyNestedJSDocIndentSpace;\n\n messages.forEach(({message, line, column, severity, ruleId}) => {\n const startLine = codeStartLine + line + zeroBasedLineIndexAdjust;\n const startCol = codeStartCol + (\n\n // This might not work for line 0, but line 0 is unlikely for examples\n line <= 1 ? nonJSPrefacingCols + firstLinePrefixLength : preTagSpaceLength\n ) + column;\n\n report(\n '@' + targetTagName + ' ' + (severity === 2 ? 'error' : 'warning') +\n (ruleId ? ' (' + ruleId + ')' : '') + ': ' +\n message,\n null,\n {\n column: startCol,\n line: startLine,\n },\n );\n });\n };\n\n sources.forEach(checkRules);\n });\n}, {\n iterateAllJsdocs: true,\n meta: {\n schema: [\n {\n additionalProperties: false,\n properties: {\n allowInlineConfig: {\n default: true,\n type: 'boolean',\n },\n baseConfig: {\n type: 'object',\n },\n captionRequired: {\n default: false,\n type: 'boolean',\n },\n checkEslintrc: {\n default: true,\n type: 'boolean',\n },\n configFile: {\n type: 'string',\n },\n exampleCodeRegex: {\n type: 'string',\n },\n matchingFileName: {\n type: 'string',\n },\n noDefaultExampleRules: {\n default: false,\n type: 'boolean',\n },\n paddedIndent: {\n default: 0,\n type: 'integer',\n },\n rejectExampleCodeRegex: {\n type: 'string',\n },\n reportUnusedDisableDirectives: {\n default: true,\n type: 'boolean',\n },\n },\n type: 'object',\n },\n ],\n type: 'suggestion',\n },\n noTrim: true,\n});\n"],"file":"checkExamples.js"}