| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent daeb7db commit 646a094
10 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -56,7 +56,7 @@ module.exports = { | |||
| 56 | 56 | schema: [], | |
| 57 | 57 | }, | |
| 58 | 58 | create(context) { | |
| 59 | - const sourceCode = context.getSourceCode(); | ||
| 59 | + const sourceCode = context.sourceCode; | ||
| 60 | 60 | ||
| 61 | 61 | return { | |
| 62 | 62 | ArrayPattern(node) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -25,41 +25,43 @@ function isTopLevel(node) { | |||
| 25 | 25 | return false; | |
| 26 | 26 | } | |
| 27 | 27 | ||
| 28 | - module.exports = (context) => { | ||
| 29 | - if (context.parserOptions.sourceType === 'module') { | ||
| 30 | - return {}; | ||
| 31 | - } | ||
| 32 | - | ||
| 33 | - function getRequiredModuleNameFromCall(node) { | ||
| 34 | - // Node has arguments and first argument is string | ||
| 35 | - if (node.arguments.length && isString(node.arguments[0])) { | ||
| 36 | - return node.arguments[0].value.trim(); | ||
| 28 | + module.exports = { | ||
| 29 | + create(context) { | ||
| 30 | + if (context.parserOptions.sourceType === 'module') { | ||
| 31 | + return {}; | ||
| 37 | 32 | } | |
| 38 | 33 | ||
| 39 | - return undefined; | ||
| 40 | - } | ||
| 34 | + function getRequiredModuleNameFromCall(node) { | ||
| 35 | + // Node has arguments and first argument is string | ||
| 36 | + if (node.arguments.length && isString(node.arguments[0])) { | ||
| 37 | + return node.arguments[0].value.trim(); | ||
| 38 | + } | ||
| 41 | 39 | ||
| 42 | - const required = new Set(); | ||
| 40 | + return undefined; | ||
| 41 | + } | ||
| 43 | 42 | ||
| 44 | - const rules = { | ||
| 45 | - CallExpression: (node) => { | ||
| 46 | - if (isRequireCall(node) && isTopLevel(node)) { | ||
| 47 | - const moduleName = getRequiredModuleNameFromCall(node); | ||
| 48 | - if (moduleName === undefined) { | ||
| 49 | - return; | ||
| 50 | - } | ||
| 51 | - if (required.has(moduleName)) { | ||
| 52 | - context.report( | ||
| 53 | - node, | ||
| 54 | - '\'{{moduleName}}\' require is duplicated.', | ||
| 55 | - { moduleName }, | ||
| 56 | - ); | ||
| 57 | - } else { | ||
| 58 | - required.add(moduleName); | ||
| 43 | + const required = new Set(); | ||
| 44 | + | ||
| 45 | + const rules = { | ||
| 46 | + CallExpression: (node) => { | ||
| 47 | + if (isRequireCall(node) && isTopLevel(node)) { | ||
| 48 | + const moduleName = getRequiredModuleNameFromCall(node); | ||
| 49 | + if (moduleName === undefined) { | ||
| 50 | + return; | ||
| 51 | + } | ||
| 52 | + if (required.has(moduleName)) { | ||
| 53 | + context.report( | ||
| 54 | + node, | ||
| 55 | + '\'{{moduleName}}\' require is duplicated.', | ||
| 56 | + { moduleName }, | ||
| 57 | + ); | ||
| 58 | + } else { | ||
| 59 | + required.add(moduleName); | ||
| 60 | + } | ||
| 59 | 61 | } | |
| 60 | - } | ||
| 61 | - }, | ||
| 62 | - }; | ||
| 62 | + }, | ||
| 63 | + }; | ||
| 63 | 64 | ||
| 64 | - return rules; | ||
| 65 | + return rules; | ||
| 66 | + }, | ||
| 65 | 67 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,7 +10,7 @@ | |||
| 10 | 10 | ||
| 11 | 11 | module.exports = { | |
| 12 | 12 | create(context) { | |
| 13 | - const sourceCode = context.getSourceCode(); | ||
| 13 | + const sourceCode = context.sourceCode; | ||
| 14 | 14 | const regexpStack = []; | |
| 15 | 15 | let regexpBuffer = []; | |
| 16 | 16 | let inRegExp = false; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,32 +24,34 @@ const suggestions = { | |||
| 24 | 24 | '—': '-', | |
| 25 | 25 | }; | |
| 26 | 26 | ||
| 27 | - module.exports = (context) => { | ||
| 27 | + module.exports = { | ||
| 28 | + create(context) { | ||
| 28 | 29 | ||
| 29 | - const reportIfError = (node, sourceCode) => { | ||
| 30 | + const reportIfError = (node, sourceCode) => { | ||
| 30 | 31 | ||
| 31 | - const matches = sourceCode.text.match(nonAsciiRegexPattern); | ||
| 32 | + const matches = sourceCode.text.match(nonAsciiRegexPattern); | ||
| 32 | 33 | ||
| 33 | - if (!matches) return; | ||
| 34 | + if (!matches) return; | ||
| 34 | 35 | ||
| 35 | - const offendingCharacter = matches[0]; | ||
| 36 | - const offendingCharacterPosition = matches.index; | ||
| 37 | - const suggestion = suggestions[offendingCharacter]; | ||
| 36 | + const offendingCharacter = matches[0]; | ||
| 37 | + const offendingCharacterPosition = matches.index; | ||
| 38 | + const suggestion = suggestions[offendingCharacter]; | ||
| 38 | 39 | ||
| 39 | - let message = `Non-ASCII character '${offendingCharacter}' detected.`; | ||
| 40 | + let message = `Non-ASCII character '${offendingCharacter}' detected.`; | ||
| 40 | 41 | ||
| 41 | - message = suggestion ? | ||
| 42 | - `${message} Consider replacing with: ${suggestion}` : | ||
| 43 | - message; | ||
| 42 | + message = suggestion ? | ||
| 43 | + `${message} Consider replacing with: ${suggestion}` : | ||
| 44 | + message; | ||
| 44 | 45 | ||
| 45 | - context.report({ | ||
| 46 | - node, | ||
| 47 | - message, | ||
| 48 | - loc: sourceCode.getLocFromIndex(offendingCharacterPosition), | ||
| 49 | - }); | ||
| 50 | - }; | ||
| 46 | + context.report({ | ||
| 47 | + node, | ||
| 48 | + message, | ||
| 49 | + loc: sourceCode.getLocFromIndex(offendingCharacterPosition), | ||
| 50 | + }); | ||
| 51 | + }; | ||
| 51 | 52 | ||
| 52 | - return { | ||
| 53 | - Program: (node) => reportIfError(node, context.getSourceCode()), | ||
| 54 | - }; | ||
| 53 | + return { | ||
| 54 | + Program: (node) => reportIfError(node, context.sourceCode), | ||
| 55 | + }; | ||
| 56 | + }, | ||
| 55 | 57 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -12,7 +12,7 @@ module.exports = { | |||
| 12 | 12 | fixable: 'code', | |
| 13 | 13 | }, | |
| 14 | 14 | create(context) { | |
| 15 | - const sourceCode = context.getSourceCode(); | ||
| 15 | + const sourceCode = context.sourceCode; | ||
| 16 | 16 | let assertImported = false; | |
| 17 | 17 | ||
| 18 | 18 | function hasSameTokens(nodeA, nodeB) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -31,7 +31,7 @@ module.exports = { | |||
| 31 | 31 | node, | |
| 32 | 32 | message: parseError(assertMethod, arg.operator), | |
| 33 | 33 | fix: (fixer) => { | |
| 34 | - const sourceCode = context.getSourceCode(); | ||
| 34 | + const sourceCode = context.sourceCode; | ||
| 35 | 35 | const left = sourceCode.getText(arg.left); | |
| 36 | 36 | const right = sourceCode.getText(arg.right); | |
| 37 | 37 | return fixer.replaceText( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,64 +3,66 @@ | |||
| 3 | 3 | const mustCall = 'CallExpression[callee.object.name="common"]' + | |
| 4 | 4 | '[callee.property.name="mustCall"]'; | |
| 5 | 5 | ||
| 6 | - module.exports = (context) => { | ||
| 7 | - function isAssertIfError(node) { | ||
| 8 | - return node.type === 'MemberExpression' && | ||
| 9 | - node.object.type === 'Identifier' && | ||
| 10 | - node.object.name === 'assert' && | ||
| 11 | - node.property.type === 'Identifier' && | ||
| 12 | - node.property.name === 'ifError'; | ||
| 13 | - } | ||
| 6 | + module.exports = { | ||
| 7 | + create(context) { | ||
| 8 | + function isAssertIfError(node) { | ||
| 9 | + return node.type === 'MemberExpression' && | ||
| 10 | + node.object.type === 'Identifier' && | ||
| 11 | + node.object.name === 'assert' && | ||
| 12 | + node.property.type === 'Identifier' && | ||
| 13 | + node.property.name === 'ifError'; | ||
| 14 | + } | ||
| 14 | 15 | ||
| 15 | - function isCallToIfError(node, errName) { | ||
| 16 | - return node.type === 'CallExpression' && | ||
| 17 | - isAssertIfError(node.callee) && | ||
| 18 | - node.arguments.length > 0 && | ||
| 19 | - node.arguments[0].type === 'Identifier' && | ||
| 20 | - node.arguments[0].name === errName; | ||
| 21 | - } | ||
| 16 | + function isCallToIfError(node, errName) { | ||
| 17 | + return node.type === 'CallExpression' && | ||
| 18 | + isAssertIfError(node.callee) && | ||
| 19 | + node.arguments.length > 0 && | ||
| 20 | + node.arguments[0].type === 'Identifier' && | ||
| 21 | + node.arguments[0].name === errName; | ||
| 22 | + } | ||
| 22 | 23 | ||
| 23 | - function bodyStartsWithCallToIfError(body, errName) { | ||
| 24 | - while (body.type === 'BlockStatement' && body.body.length > 0) | ||
| 25 | - body = body.body[0]; | ||
| 24 | + function bodyStartsWithCallToIfError(body, errName) { | ||
| 25 | + while (body.type === 'BlockStatement' && body.body.length > 0) | ||
| 26 | + body = body.body[0]; | ||
| 26 | 27 | ||
| 27 | - let expr; | ||
| 28 | - switch (body.type) { | ||
| 29 | - case 'ReturnStatement': | ||
| 30 | - expr = body.argument; | ||
| 31 | - break; | ||
| 32 | - case 'ExpressionStatement': | ||
| 33 | - expr = body.expression; | ||
| 34 | - break; | ||
| 35 | - default: | ||
| 36 | - expr = body; | ||
| 37 | - } | ||
| 28 | + let expr; | ||
| 29 | + switch (body.type) { | ||
| 30 | + case 'ReturnStatement': | ||
| 31 | + expr = body.argument; | ||
| 32 | + break; | ||
| 33 | + case 'ExpressionStatement': | ||
| 34 | + expr = body.expression; | ||
| 35 | + break; | ||
| 36 | + default: | ||
| 37 | + expr = body; | ||
| 38 | + } | ||
| 38 | 39 | ||
| 39 | - return isCallToIfError(expr, errName); | ||
| 40 | - } | ||
| 40 | + return isCallToIfError(expr, errName); | ||
| 41 | + } | ||
| 41 | 42 | ||
| 42 | - return { | ||
| 43 | - [`${mustCall}:exit`]: (mustCall) => { | ||
| 44 | - if (mustCall.arguments.length > 0) { | ||
| 45 | - const callback = mustCall.arguments[0]; | ||
| 46 | - if (isAssertIfError(callback)) { | ||
| 47 | - context.report(mustCall, 'Please use common.mustSucceed instead of ' + | ||
| 48 | - 'common.mustCall(assert.ifError).'); | ||
| 49 | - } | ||
| 43 | + return { | ||
| 44 | + [`${mustCall}:exit`]: (mustCall) => { | ||
| 45 | + if (mustCall.arguments.length > 0) { | ||
| 46 | + const callback = mustCall.arguments[0]; | ||
| 47 | + if (isAssertIfError(callback)) { | ||
| 48 | + context.report(mustCall, 'Please use common.mustSucceed instead of ' + | ||
| 49 | + 'common.mustCall(assert.ifError).'); | ||
| 50 | + } | ||
| 50 | 51 | ||
| 51 | - if (callback.type === 'ArrowFunctionExpression' || | ||
| 52 | - callback.type === 'FunctionExpression') { | ||
| 53 | - if (callback.params.length > 0 && | ||
| 54 | - callback.params[0].type === 'Identifier') { | ||
| 55 | - const errName = callback.params[0].name; | ||
| 56 | - if (bodyStartsWithCallToIfError(callback.body, errName)) { | ||
| 57 | - context.report(mustCall, 'Please use common.mustSucceed instead' + | ||
| 58 | - ' of common.mustCall with' + | ||
| 59 | - ' assert.ifError.'); | ||
| 52 | + if (callback.type === 'ArrowFunctionExpression' || | ||
| 53 | + callback.type === 'FunctionExpression') { | ||
| 54 | + if (callback.params.length > 0 && | ||
| 55 | + callback.params[0].type === 'Identifier') { | ||
| 56 | + const errName = callback.params[0].name; | ||
| 57 | + if (bodyStartsWithCallToIfError(callback.body, errName)) { | ||
| 58 | + context.report(mustCall, 'Please use common.mustSucceed instead' + | ||
| 59 | + ' of common.mustCall with' + | ||
| 60 | + ' assert.ifError.'); | ||
| 61 | + } | ||
| 60 | 62 | } | |
| 61 | 63 | } | |
| 62 | 64 | } | |
| 63 | - } | ||
| 64 | - }, | ||
| 65 | - }; | ||
| 65 | + }, | ||
| 66 | + }; | ||
| 67 | + }, | ||
| 66 | 68 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -75,9 +75,27 @@ module.exports = { | |||
| 75 | 75 | messages: { | |
| 76 | 76 | error: 'Use `const { {{name}} } = primordials;` instead of the global.', | |
| 77 | 77 | }, | |
| 78 | + schema: { | ||
| 79 | + type: 'array', | ||
| 80 | + items: [ | ||
| 81 | + { | ||
| 82 | + type: 'object', | ||
| 83 | + required: ['name'], | ||
| 84 | + properties: { | ||
| 85 | + name: { type: 'string' }, | ||
| 86 | + ignore: { | ||
| 87 | + type: 'array', | ||
| 88 | + items: { type: 'string' }, | ||
| 89 | + }, | ||
| 90 | + into: { type: 'string' }, | ||
| 91 | + }, | ||
| 92 | + additionalProperties: false, | ||
| 93 | + }, | ||
| 94 | + ], | ||
| 95 | + }, | ||
| 78 | 96 | }, | |
| 79 | 97 | create(context) { | |
| 80 | - const globalScope = context.getSourceCode().scopeManager.globalScope; | ||
| 98 | + const globalScope = context.sourceCode.scopeManager.globalScope; | ||
| 81 | 99 | ||
| 82 | 100 | const nameMap = new Map(); | |
| 83 | 101 | const renameMap = new Map(); | |
@@ -110,7 +128,7 @@ module.exports = { | |||
| 110 | 128 | } | |
| 111 | 129 | const name = node.name; | |
| 112 | 130 | const parent = getDestructuringAssignmentParent( | |
| 113 | - context.getScope(), | ||
| 131 | + context.sourceCode.getScope(node), | ||
| 114 | 132 | node, | |
| 115 | 133 | ); | |
| 116 | 134 | const parentName = parent?.name; | |
@@ -155,7 +173,7 @@ module.exports = { | |||
| 155 | 173 | } | |
| 156 | 174 | ||
| 157 | 175 | const variables = | |
| 158 | - context.getSourceCode().scopeManager.getDeclaredVariables(node); | ||
| 176 | + context.sourceCode.scopeManager.getDeclaredVariables(node); | ||
| 159 | 177 | if (variables.length === 0) { | |
| 160 | 178 | context.report({ | |
| 161 | 179 | node, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,8 +7,8 @@ | |||
| 7 | 7 | 'use strict'; | |
| 8 | 8 | ||
| 9 | 9 | // Cribbed from `eslint-module-utils/declaredScope` | |
| 10 | - function declaredScope(context, name) { | ||
| 11 | - const references = context.getScope().references; | ||
| 10 | + function declaredScope(context, node, name) { | ||
| 11 | + const references = context.sourceCode.getScope(node).references; | ||
| 12 | 12 | const reference = references.find((x) => x.identifier.name === name); | |
| 13 | 13 | if (!reference) return undefined; | |
| 14 | 14 | return reference.resolved.scope.type; | |
@@ -33,12 +33,12 @@ module.exports = { | |||
| 33 | 33 | [callee.type="MemberExpression"][callee.object.name="Object"][callee.property.name="create"]\ | |
| 34 | 34 | )'(node) { | |
| 35 | 35 | if (node.callee.type === 'MemberExpression') { | |
| 36 | - const scope = declaredScope(context, node.callee.object); | ||
| 36 | + const scope = declaredScope(context, node, node.callee.object); | ||
| 37 | 37 | if (scope && scope !== 'module' && scope !== 'global') { | |
| 38 | 38 | return; | |
| 39 | 39 | } | |
| 40 | 40 | } | |
| 41 | - const value = context.getSourceCode().getText(node.arguments[0]); | ||
| 41 | + const value = context.sourceCode.getText(node.arguments[0]); | ||
| 42 | 42 | context.report({ | |
| 43 | 43 | node, | |
| 44 | 44 | messageId: 'error', | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -46,7 +46,7 @@ module.exports = { | |||
| 46 | 46 | message: 'Every object must have __proto__: null', | |
| 47 | 47 | fix: function(fixer) { | |
| 48 | 48 | // Generate the fix suggestion to add __proto__: null | |
| 49 | - const sourceCode = context.getSourceCode(); | ||
| 49 | + const sourceCode = context.sourceCode; | ||
| 50 | 50 | const firstProperty = properties[0]; | |
| 51 | 51 | const firstPropertyToken = sourceCode.getFirstToken(firstProperty); | |
| 52 | 52 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments