Skip to content

Commit c12b522

Browse files
committed
chore: adjust comments
adjust comments
1 parent 761294c commit c12b522

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

eslint-plugin-prettier.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,12 @@ let prettierFormat;
5454
function reportDifference(context, difference) {
5555
const { operation, offset, deleteText = '', insertText = '' } = difference;
5656
const range = /** @type {Range} */ ([offset, offset + deleteText.length]);
57-
const [start, end] = range.map(index => {
58-
const sourceCode = context.sourceCode ?? context.getSourceCode(); // `context.sourceCode` was added in ESLint v8.40.0. By checking both the property and the method, breaking change is avoided. TODO: Only use property when requiring a minimum version of v8.40.0 or higher of ESLint.
59-
return sourceCode.getLocFromIndex(index);
60-
});
57+
// `context.getSourceCode()` was deprecated in ESLint v8.40.0 and replaced
58+
// with the `sourceCode` property.
59+
// TODO: Only use property when our eslint peerDependency is >=8.40.0.
60+
const [start, end] = range.map(index =>
61+
(context.sourceCode ?? context.getSourceCode()).getLocFromIndex(index),
62+
);
6163

6264
context.report({
6365
messageId: operation,
@@ -131,15 +133,26 @@ const eslintPluginPrettier = {
131133
*/
132134
const fileInfoOptions =
133135
(context.options[1] && context.options[1].fileInfoOptions) || {};
134-
const sourceCode = context.sourceCode ?? context.getSourceCode(); // `context.sourceCode` was added in ESLint v8.40.0. By checking both the property and the method, breaking change is avoided. TODO: Only use property when requiring a minimum version of v8.40.0 or higher of ESLint.
135-
const filepath = context.filename ?? context.getFilename(); // `context.filename` was added in ESLint v8.40.0. By checking both the property and the method, breaking change is avoided. TODO: Only use property when requiring a minimum version of v8.40.0 or higher of ESLint.
136+
137+
// `context.getSourceCode()` was deprecated in ESLint v8.40.0 and replaced
138+
// with the `sourceCode` property.
139+
// TODO: Only use property when our eslint peerDependency is >=8.40.0.
140+
const sourceCode = context.sourceCode ?? context.getSourceCode();
141+
// `context.getFilename()` was deprecated in ESLint v8.40.0 and replaced
142+
// with the `filename` property.
143+
// TODO: Only use property when our eslint peerDependency is >=8.40.0.
144+
const filepath = context.filename ?? context.getFilename();
145+
136146
// Processors that extract content from a file, such as the markdown
137147
// plugin extracting fenced code blocks may choose to specify virtual
138148
// file paths. If this is the case then we need to resolve prettier
139149
// config and file info using the on-disk path instead of the virtual
140150
// path.
151+
// `context.getPhysicalFilename()` was deprecated in ESLint v8.40.0 and replaced
152+
// with the `physicalFilename` property.
153+
// TODO: Only use property when our eslint peerDependency is >=8.40.0.
141154
const onDiskFilepath =
142-
context.physicalFilename ?? context.getPhysicalFilename(); // `context.physicalFilename` was added in ESLint v8.40.0. By checking both the property and the method, breaking change is avoided. TODO: Only use property when requiring a minimum version of v8.40.0 or higher of ESLint.
155+
context.physicalFilename ?? context.getPhysicalFilename();
143156
const source = sourceCode.text;
144157

145158
return {

0 commit comments

Comments
 (0)