no-tabs.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /**
  2. * @fileoverview Rule to check for tabs inside a file
  3. * @author Gyandeep Singh
  4. */
  5. "use strict";
  6. //------------------------------------------------------------------------------
  7. // Helpers
  8. //------------------------------------------------------------------------------
  9. const regex = /\t/;
  10. //------------------------------------------------------------------------------
  11. // Public Interface
  12. //------------------------------------------------------------------------------
  13. module.exports = {
  14. meta: {
  15. docs: {
  16. description: "disallow all tabs",
  17. category: "Stylistic Issues",
  18. recommended: false,
  19. url: "https://eslint.org/docs/rules/no-tabs"
  20. },
  21. schema: []
  22. },
  23. create(context) {
  24. return {
  25. Program(node) {
  26. context.getSourceCode().getLines().forEach((line, index) => {
  27. const match = regex.exec(line);
  28. if (match) {
  29. context.report({
  30. node,
  31. loc: {
  32. line: index + 1,
  33. column: match.index + 1
  34. },
  35. message: "Unexpected tab character."
  36. });
  37. }
  38. });
  39. }
  40. };
  41. }
  42. };