file-context.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /**
  2. * @fileoverview The FileContext class.
  3. * @author Nicholas C. Zakas
  4. */
  5. "use strict";
  6. /**
  7. * Represents a file context that the linter can use to lint a file.
  8. */
  9. class FileContext {
  10. /**
  11. * The current working directory.
  12. * @type {string}
  13. */
  14. cwd;
  15. /**
  16. * The filename of the file being linted.
  17. * @type {string}
  18. */
  19. filename;
  20. /**
  21. * The physical filename of the file being linted.
  22. * @type {string}
  23. */
  24. physicalFilename;
  25. /**
  26. * The source code of the file being linted.
  27. * @type {SourceCode}
  28. */
  29. sourceCode;
  30. /**
  31. * The parser options for the file being linted.
  32. * @type {Record<string, unknown>}
  33. * @deprecated Use `languageOptions` instead.
  34. */
  35. parserOptions;
  36. /**
  37. * The path to the parser used to parse this file.
  38. * @type {string}
  39. * @deprecated No longer supported.
  40. */
  41. parserPath;
  42. /**
  43. * The language options used when parsing this file.
  44. * @type {Record<string, unknown>}
  45. */
  46. languageOptions;
  47. /**
  48. * The settings for the file being linted.
  49. * @type {Record<string, unknown>}
  50. */
  51. settings;
  52. /**
  53. * Creates a new instance.
  54. * @param {Object} config The configuration object for the file context.
  55. * @param {string} config.cwd The current working directory.
  56. * @param {string} config.filename The filename of the file being linted.
  57. * @param {string} config.physicalFilename The physical filename of the file being linted.
  58. * @param {SourceCode} config.sourceCode The source code of the file being linted.
  59. * @param {Record<string, unknown>} config.parserOptions The parser options for the file being linted.
  60. * @param {string} config.parserPath The path to the parser used to parse this file.
  61. * @param {Record<string, unknown>} config.languageOptions The language options used when parsing this file.
  62. * @param {Record<string, unknown>} config.settings The settings for the file being linted.
  63. */
  64. constructor({
  65. cwd,
  66. filename,
  67. physicalFilename,
  68. sourceCode,
  69. parserOptions,
  70. parserPath,
  71. languageOptions,
  72. settings
  73. }) {
  74. this.cwd = cwd;
  75. this.filename = filename;
  76. this.physicalFilename = physicalFilename;
  77. this.sourceCode = sourceCode;
  78. this.parserOptions = parserOptions;
  79. this.parserPath = parserPath;
  80. this.languageOptions = languageOptions;
  81. this.settings = settings;
  82. Object.freeze(this);
  83. }
  84. /**
  85. * Gets the current working directory.
  86. * @returns {string} The current working directory.
  87. * @deprecated Use `cwd` instead.
  88. */
  89. getCwd() {
  90. return this.cwd;
  91. }
  92. /**
  93. * Gets the filename of the file being linted.
  94. * @returns {string} The filename of the file being linted.
  95. * @deprecated Use `filename` instead.
  96. */
  97. getFilename() {
  98. return this.filename;
  99. }
  100. /**
  101. * Gets the physical filename of the file being linted.
  102. * @returns {string} The physical filename of the file being linted.
  103. * @deprecated Use `physicalFilename` instead.
  104. */
  105. getPhysicalFilename() {
  106. return this.physicalFilename;
  107. }
  108. /**
  109. * Gets the source code of the file being linted.
  110. * @returns {SourceCode} The source code of the file being linted.
  111. * @deprecated Use `sourceCode` instead.
  112. */
  113. getSourceCode() {
  114. return this.sourceCode;
  115. }
  116. }
  117. exports.FileContext = FileContext;