Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
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.

template-tag-spacing.js 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /**
  2. * @fileoverview Rule to check spacing between template tags and their literals
  3. * @author Jonathan Wilsson
  4. */
  5. "use strict";
  6. //------------------------------------------------------------------------------
  7. // Rule Definition
  8. //------------------------------------------------------------------------------
  9. module.exports = {
  10. meta: {
  11. type: "layout",
  12. docs: {
  13. description: "require or disallow spacing between template tags and their literals",
  14. category: "Stylistic Issues",
  15. recommended: false,
  16. url: "https://eslint.org/docs/rules/template-tag-spacing"
  17. },
  18. fixable: "whitespace",
  19. schema: [
  20. { enum: ["always", "never"] }
  21. ],
  22. messages: {
  23. unexpected: "Unexpected space between template tag and template literal.",
  24. missing: "Missing space between template tag and template literal."
  25. }
  26. },
  27. create(context) {
  28. const never = context.options[0] !== "always";
  29. const sourceCode = context.getSourceCode();
  30. /**
  31. * Check if a space is present between a template tag and its literal
  32. * @param {ASTNode} node node to evaluate
  33. * @returns {void}
  34. * @private
  35. */
  36. function checkSpacing(node) {
  37. const tagToken = sourceCode.getTokenBefore(node.quasi);
  38. const literalToken = sourceCode.getFirstToken(node.quasi);
  39. const hasWhitespace = sourceCode.isSpaceBetweenTokens(tagToken, literalToken);
  40. if (never && hasWhitespace) {
  41. context.report({
  42. node,
  43. loc: {
  44. start: tagToken.loc.end,
  45. end: literalToken.loc.start
  46. },
  47. messageId: "unexpected",
  48. fix(fixer) {
  49. const comments = sourceCode.getCommentsBefore(node.quasi);
  50. // Don't fix anything if there's a single line comment after the template tag
  51. if (comments.some(comment => comment.type === "Line")) {
  52. return null;
  53. }
  54. return fixer.replaceTextRange(
  55. [tagToken.range[1], literalToken.range[0]],
  56. comments.reduce((text, comment) => text + sourceCode.getText(comment), "")
  57. );
  58. }
  59. });
  60. } else if (!never && !hasWhitespace) {
  61. context.report({
  62. node,
  63. loc: {
  64. start: node.loc.start,
  65. end: literalToken.loc.start
  66. },
  67. messageId: "missing",
  68. fix(fixer) {
  69. return fixer.insertTextAfter(tagToken, " ");
  70. }
  71. });
  72. }
  73. }
  74. return {
  75. TaggedTemplateExpression: checkSpacing
  76. };
  77. }
  78. };