项目原始demo,不改动
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
このリポジトリはアーカイブされています。 ファイルの閲覧とクローンは可能ですが、プッシュや、課題・プルリクエストのオープンはできません。
 
 
 
 

45 行
1.1 KiB

  1. /**
  2. * @fileoverview Rule to restrict what can be thrown as an exception.
  3. * @author Dieter Oberkofler
  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 throwing literals as exceptions",
  14. category: "Best Practices",
  15. recommended: false,
  16. url: "https://eslint.org/docs/rules/no-throw-literal"
  17. },
  18. schema: []
  19. },
  20. create(context) {
  21. return {
  22. ThrowStatement(node) {
  23. if (!astUtils.couldBeError(node.argument)) {
  24. context.report({ node, message: "Expected an object to be thrown." });
  25. } else if (node.argument.type === "Identifier") {
  26. if (node.argument.name === "undefined") {
  27. context.report({ node, message: "Do not throw undefined." });
  28. }
  29. }
  30. }
  31. };
  32. }
  33. };