Ohm-Management - Projektarbeit B-ME
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.

no-spaced-func.js 2.3KB

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