web 3d图形渲染器
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.

66 lines
1.7 KiB

  1. /**
  2. * @fileoverview Comments inside children section of tag should be placed inside braces.
  3. * @author Ben Vinegar
  4. */
  5. 'use strict';
  6. const docsUrl = require('../util/docsUrl');
  7. // ------------------------------------------------------------------------------
  8. // Rule Definition
  9. // ------------------------------------------------------------------------------
  10. function checkText(node, context) {
  11. // since babel-eslint has the wrong node.raw, we'll get the source text
  12. const rawValue = context.getSourceCode().getText(node);
  13. if (/^\s*\/(\/|\*)/m.test(rawValue)) {
  14. // inside component, e.g. <div>literal</div>
  15. if (
  16. node.parent.type !== 'JSXAttribute'
  17. && node.parent.type !== 'JSXExpressionContainer'
  18. && node.parent.type.indexOf('JSX') !== -1
  19. ) {
  20. context.report({
  21. node,
  22. messageId: 'putCommentInBraces'
  23. });
  24. }
  25. }
  26. }
  27. module.exports = {
  28. meta: {
  29. docs: {
  30. description: 'Comments inside children section of tag should be placed inside braces',
  31. category: 'Possible Errors',
  32. recommended: true,
  33. url: docsUrl('jsx-no-comment-textnodes')
  34. },
  35. messages: {
  36. putCommentInBraces: 'Comments inside children section of tag should be placed inside braces'
  37. },
  38. schema: [{
  39. type: 'object',
  40. properties: {},
  41. additionalProperties: false
  42. }]
  43. },
  44. create(context) {
  45. // --------------------------------------------------------------------------
  46. // Public
  47. // --------------------------------------------------------------------------
  48. return {
  49. Literal(node) {
  50. checkText(node, context);
  51. },
  52. JSXText(node) {
  53. checkText(node, context);
  54. }
  55. };
  56. }
  57. };