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