Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

no-tabs.js 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 tabRegex = /\t+/g;
  10. const anyNonWhitespaceRegex = /\S/;
  11. //------------------------------------------------------------------------------
  12. // Public Interface
  13. //------------------------------------------------------------------------------
  14. module.exports = {
  15. meta: {
  16. type: "layout",
  17. docs: {
  18. description: "disallow all tabs",
  19. category: "Stylistic Issues",
  20. recommended: false,
  21. url: "https://eslint.org/docs/rules/no-tabs"
  22. },
  23. schema: [{
  24. type: "object",
  25. properties: {
  26. allowIndentationTabs: {
  27. type: "boolean"
  28. }
  29. },
  30. additionalProperties: false
  31. }]
  32. },
  33. create(context) {
  34. const sourceCode = context.getSourceCode();
  35. const allowIndentationTabs = context.options && context.options[0] && context.options[0].allowIndentationTabs;
  36. return {
  37. Program(node) {
  38. sourceCode.getLines().forEach((line, index) => {
  39. let match;
  40. while ((match = tabRegex.exec(line)) !== null) {
  41. if (allowIndentationTabs && !anyNonWhitespaceRegex.test(line.slice(0, match.index))) {
  42. continue;
  43. }
  44. context.report({
  45. node,
  46. loc: {
  47. line: index + 1,
  48. column: match.index
  49. },
  50. message: "Unexpected tab character."
  51. });
  52. }
  53. });
  54. }
  55. };
  56. }
  57. };