unambiguous.js 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. 'use strict';
  2. var _unambiguous = require('eslint-module-utils/unambiguous');
  3. var _docsUrl = require('../docsUrl');var _docsUrl2 = _interopRequireDefault(_docsUrl);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { 'default': obj };} /**
  4. * @fileOverview Report modules that could parse incorrectly as scripts.
  5. * @author Ben Mosher
  6. */module.exports = { meta: {
  7. type: 'suggestion',
  8. docs: {
  9. category: 'Module systems',
  10. description: 'Forbid potentially ambiguous parse goal (`script` vs. `module`).',
  11. url: (0, _docsUrl2['default'])('unambiguous') },
  12. schema: [] },
  13. create: function () {function create(context) {
  14. // ignore non-modules
  15. if (context.parserOptions.sourceType !== 'module') {
  16. return {};
  17. }
  18. return {
  19. Program: function () {function Program(ast) {
  20. if (!(0, _unambiguous.isModule)(ast)) {
  21. context.report({
  22. node: ast,
  23. message: 'This module could be parsed as a valid script.' });
  24. }
  25. }return Program;}() };
  26. }return create;}() };
  27. //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy91bmFtYmlndW91cy5qcyJdLCJuYW1lcyI6WyJtb2R1bGUiLCJleHBvcnRzIiwibWV0YSIsInR5cGUiLCJkb2NzIiwiY2F0ZWdvcnkiLCJkZXNjcmlwdGlvbiIsInVybCIsInNjaGVtYSIsImNyZWF0ZSIsImNvbnRleHQiLCJwYXJzZXJPcHRpb25zIiwic291cmNlVHlwZSIsIlByb2dyYW0iLCJhc3QiLCJyZXBvcnQiLCJub2RlIiwibWVzc2FnZSJdLCJtYXBwaW5ncyI6Ijs7Ozs7QUFLQTtBQUNBLHFDLGlKQU5BOzs7eUxBUUFBLE9BQU9DLE9BQVAsR0FBaUIsRUFDZkMsTUFBTTtBQUNKQyxVQUFNLFlBREY7QUFFSkMsVUFBTTtBQUNKQyxnQkFBVSxnQkFETjtBQUVKQyxtQkFBYSxr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