no-document-cookie.js 793 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. 'use strict';
  2. const getPropertyName = require('./utils/get-property-name.js');
  3. const MESSAGE_ID = 'no-document-cookie';
  4. const messages = {
  5. [MESSAGE_ID]: 'Do not use `document.cookie` directly.',
  6. };
  7. const selector = [
  8. 'AssignmentExpression',
  9. '>',
  10. 'MemberExpression.left',
  11. '[object.type="Identifier"]',
  12. '[object.name="document"]',
  13. ].join('');
  14. /** @param {import('eslint').Rule.RuleContext} context */
  15. const create = context => ({
  16. [selector](node) {
  17. if (getPropertyName(node, context.getScope()) !== 'cookie') {
  18. return;
  19. }
  20. return {
  21. node,
  22. messageId: MESSAGE_ID,
  23. };
  24. },
  25. });
  26. /** @type {import('eslint').Rule.RuleModule} */
  27. module.exports = {
  28. create,
  29. meta: {
  30. type: 'problem',
  31. docs: {
  32. description: 'Do not use `document.cookie` directly.',
  33. },
  34. messages,
  35. },
  36. };