Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16.17.0
16
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ Next we need to configure your project to use the extension. To do that, we're g
"editor.formatOnSave": true, // optional
"editor.formatOnSaveMode": "file", // required to format on save
"files.autoSave": "onFocusChange" // optional but recommended
"vs-code-prettier-eslint.prettierLast": "false" // set as "true" to run 'prettier' last not first
}
```

Expand Down
Empty file removed jest.setup.js
Empty file.
22 changes: 20 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"@semantic-release/changelog": "^6.0.2",
"@semantic-release/exec": "^6.0.3",
"@semantic-release/git": "^10.0.1",
"@vscode/test-electron": "^2.2.1",
"@vscode/test-electron": "^2.2.3",
"all-contributors-cli": "^6.24.0",
"esbuild": "^0.16.14",
"esbuild-plugin-text-replace": "^1.2.0",
Expand All @@ -78,5 +78,23 @@
"find-up": "^6.3.0",
"ignore": "^5.2.4",
"prettier-eslint": "^15.0.1"
},
"contributes": {
"configuration": {
"title": "Prettier Eslint",
"properties": {
"vs-code-prettier-eslint.prettierLast": {
"type": "boolean",
"default": false,
"description": "Run Prettier Last"
}
}
}
},
"__metadata": {
"id": "d4b06bd6-36a0-469f-be55-c0a73413b688",
"publisherDisplayName": "Rebecca Vest",
"publisherId": "b95e678b-a11b-44b4-b281-6b521c2005bc",
"isPreReleaseVersion": false
}
}
}
6 changes: 6 additions & 0 deletions src/extension.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
/* eslint-disable import/no-unresolved */
/**
* @typedef {import('vscode')}
*/

import {
languages, window, TextEdit, workspace,
} from 'vscode';
Expand All @@ -24,9 +28,11 @@ async function formatter(document, range) {
outputChannel.appendLine('File ignored. Matches entry in .eslintignore or .prettierignore');
} else {
const text = document.getText(range);
const extensionConfig = workspace?.getConfiguration('vs-code-prettier-eslint');
const formatted = await format({
text,
filePath: document.fileName,
extensionConfig,
});
return [TextEdit.replace(range, formatted)];
}
Expand Down
3 changes: 2 additions & 1 deletion src/formatter.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import format from 'prettier-eslint';

export default function formatText({ text, filePath }) {
export default function formatText({ text, filePath, extensionConfig }) {
return format({
text,
filePath,
prettierLast: extensionConfig?.prettierLast || false,
});
}
1 change: 1 addition & 0 deletions test/runTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ async function main() {

// Download VS Code, unzip it and run the integration test
await runTests({
version: '1.73.1',
extensionDevelopmentPath,
extensionTestsPath,
launchArgs: [
Expand Down
11 changes: 11 additions & 0 deletions test/suite/__snapshots__/extension.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,14 @@ exports[`Extension Test Suite Formats document using .eslintrc 1`] = `
export { options };
"
`;

exports[`Extension Test Suite setting "prettierLast" makes prettier run last 1`] = `
"const options = {
first: "hello, world",
second: true,
internationalizing: true,
}

export { options }
"
`;
14 changes: 14 additions & 0 deletions test/suite/extension.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@ describe('Extension Test Suite', () => {

expect(formatted).toMatchSnapshot();
});

test('setting "prettierLast" makes prettier run last', async () => {
const content = fs.readFileSync(sourceFile).toString().replace('/* eslint-disable */\n', '');
const filePath = `${basePath}/temp/test.js`;
fs.writeFileSync(filePath, content, { overwrite: true });
const document = await helper.openFile(filePath);
const config = vscode.workspace.getConfiguration('vs-code-prettier-eslint');
await config.update('prettierLast', 'true', vscode.ConfigurationTarget.Global);
await vscode.commands.executeCommand('editor.action.formatDocument');
await config.update('prettierLast', undefined, vscode.ConfigurationTarget.Global);

const formatted = document.getText();
expect(formatted).toMatchSnapshot();
});
afterAll(() => {
helper.clearConfig('[javascript]');
});
Expand Down
Loading