no-trailing-commas.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /**
  2. * @author Toru Nagashima <https://github.com/mysticatea>
  3. * See LICENSE file in root directory for full license.
  4. */
  5. "use strict"
  6. const { isCommaToken } = require("../utils")
  7. module.exports = {
  8. meta: {
  9. docs: {
  10. description: "disallow trailing commas in array/object literals.",
  11. category: "ES5",
  12. recommended: false,
  13. url:
  14. "http://mysticatea.github.io/eslint-plugin-es/rules/no-trailing-commas.html",
  15. },
  16. fixable: null,
  17. schema: [],
  18. messages: {
  19. forbidden:
  20. "ES5 trailing commas in array/object literals are forbidden.",
  21. },
  22. },
  23. create(context) {
  24. const sourceCode = context.getSourceCode()
  25. return {
  26. "ArrayExpression, ArrayPattern, ObjectExpression, ObjectPattern"(
  27. node
  28. ) {
  29. const token = sourceCode.getLastToken(node, 1)
  30. if (isCommaToken(token)) {
  31. context.report({ node, messageId: "forbidden" })
  32. }
  33. },
  34. }
  35. },
  36. }