项目原始demo,不改动
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
Este repositório está arquivado. Você pode visualizar os arquivos e realizar clone, mas não poderá realizar push nem abrir issues e pull requests.
 
 
 
 

67 linhas
2.2 KiB

  1. /**
  2. * @fileoverview Enforces or disallows inline comments.
  3. * @author Greg Cochard
  4. */
  5. "use strict";
  6. const astUtils = require("../ast-utils");
  7. //------------------------------------------------------------------------------
  8. // Rule Definition
  9. //------------------------------------------------------------------------------
  10. module.exports = {
  11. meta: {
  12. docs: {
  13. description: "disallow inline comments after code",
  14. category: "Stylistic Issues",
  15. recommended: false,
  16. url: "https://eslint.org/docs/rules/no-inline-comments"
  17. },
  18. schema: []
  19. },
  20. create(context) {
  21. const sourceCode = context.getSourceCode();
  22. /**
  23. * Will check that comments are not on lines starting with or ending with code
  24. * @param {ASTNode} node The comment node to check
  25. * @private
  26. * @returns {void}
  27. */
  28. function testCodeAroundComment(node) {
  29. // Get the whole line and cut it off at the start of the comment
  30. const startLine = String(sourceCode.lines[node.loc.start.line - 1]);
  31. const endLine = String(sourceCode.lines[node.loc.end.line - 1]);
  32. const preamble = startLine.slice(0, node.loc.start.column).trim();
  33. // Also check after the comment
  34. const postamble = endLine.slice(node.loc.end.column).trim();
  35. // Check that this comment isn't an ESLint directive
  36. const isDirective = astUtils.isDirectiveComment(node);
  37. // Should be empty if there was only whitespace around the comment
  38. if (!isDirective && (preamble || postamble)) {
  39. context.report({ node, message: "Unexpected comment inline with code." });
  40. }
  41. }
  42. //--------------------------------------------------------------------------
  43. // Public
  44. //--------------------------------------------------------------------------
  45. return {
  46. Program() {
  47. const comments = sourceCode.getAllComments();
  48. comments.filter(token => token.type !== "Shebang").forEach(testCodeAroundComment);
  49. }
  50. };
  51. }
  52. };