require-direct-export.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /**
  2. * @fileoverview require the component to be directly exported
  3. * @author Hiroki Osame <hiroki.osame@gmail.com>
  4. */
  5. 'use strict'
  6. const utils = require('../utils')
  7. // ------------------------------------------------------------------------------
  8. // Rule Definition
  9. // ------------------------------------------------------------------------------
  10. module.exports = {
  11. meta: {
  12. type: 'suggestion',
  13. docs: {
  14. description: 'require the component to be directly exported',
  15. category: undefined,
  16. url: 'https://eslint.vuejs.org/rules/require-direct-export.html'
  17. },
  18. fixable: null, // or "code" or "whitespace"
  19. schema: []
  20. },
  21. create (context) {
  22. const filePath = context.getFilename()
  23. return {
  24. 'ExportDefaultDeclaration:exit' (node) {
  25. if (!utils.isVueFile(filePath)) return
  26. const isObjectExpression = (
  27. node.type === 'ExportDefaultDeclaration' &&
  28. node.declaration.type === 'ObjectExpression'
  29. )
  30. if (!isObjectExpression) {
  31. context.report({
  32. node,
  33. message: `Expected the component literal to be directly exported.`
  34. })
  35. }
  36. }
  37. }
  38. }
  39. }