项目原始demo,不改动
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Deze repo is gearchiveerd. U kunt bestanden bekijken en het klonen, maar niet pushen of problemen/pull-requests openen.
 
 
 
 

77 regels
2.3 KiB

  1. /**
  2. * @fileoverview Rule to check that spaced function application
  3. * @author Matt DuVall <http://www.mattduvall.com>
  4. * @deprecated in ESLint v3.3.0
  5. */
  6. "use strict";
  7. //------------------------------------------------------------------------------
  8. // Rule Definition
  9. //------------------------------------------------------------------------------
  10. module.exports = {
  11. meta: {
  12. docs: {
  13. description: "disallow spacing between function identifiers and their applications (deprecated)",
  14. category: "Stylistic Issues",
  15. recommended: false,
  16. replacedBy: ["func-call-spacing"],
  17. url: "https://eslint.org/docs/rules/no-spaced-func"
  18. },
  19. deprecated: true,
  20. fixable: "whitespace",
  21. schema: []
  22. },
  23. create(context) {
  24. const sourceCode = context.getSourceCode();
  25. /**
  26. * Check if open space is present in a function name
  27. * @param {ASTNode} node node to evaluate
  28. * @returns {void}
  29. * @private
  30. */
  31. function detectOpenSpaces(node) {
  32. const lastCalleeToken = sourceCode.getLastToken(node.callee);
  33. let prevToken = lastCalleeToken,
  34. parenToken = sourceCode.getTokenAfter(lastCalleeToken);
  35. // advances to an open parenthesis.
  36. while (
  37. parenToken &&
  38. parenToken.range[1] < node.range[1] &&
  39. parenToken.value !== "("
  40. ) {
  41. prevToken = parenToken;
  42. parenToken = sourceCode.getTokenAfter(parenToken);
  43. }
  44. // look for a space between the callee and the open paren
  45. if (parenToken &&
  46. parenToken.range[1] < node.range[1] &&
  47. sourceCode.isSpaceBetweenTokens(prevToken, parenToken)
  48. ) {
  49. context.report({
  50. node,
  51. loc: lastCalleeToken.loc.start,
  52. message: "Unexpected space between function name and paren.",
  53. fix(fixer) {
  54. return fixer.removeRange([prevToken.range[1], parenToken.range[0]]);
  55. }
  56. });
  57. }
  58. }
  59. return {
  60. CallExpression: detectOpenSpaces,
  61. NewExpression: detectOpenSpaces
  62. };
  63. }
  64. };