no-document-cookie.js 685 B

12345678910111213141516171819202122232425
  1. 'use strict';
  2. const {GlobalReferenceTracker} = require('./utils/global-reference-tracker.js');
  3. const MESSAGE_ID = 'no-document-cookie';
  4. const messages = {
  5. [MESSAGE_ID]: 'Do not use `document.cookie` directly.',
  6. };
  7. const tracker = new GlobalReferenceTracker({
  8. object: 'document.cookie',
  9. filter: ({node}) => node.parent.type === 'AssignmentExpression' && node.parent.left === node,
  10. handle: ({node}) => ({node, messageId: MESSAGE_ID}),
  11. });
  12. /** @type {import('eslint').Rule.RuleModule} */
  13. module.exports = {
  14. create: context => tracker.createListeners(context),
  15. meta: {
  16. type: 'problem',
  17. docs: {
  18. description: 'Do not use `document.cookie` directly.',
  19. },
  20. messages,
  21. },
  22. };