Skip to content
Open
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
9 changes: 9 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@
"contributions": [
"doc"
]
},
{
"login": "jungwookim",
"name": "jungwoo",
"avatar_url": "https://avatars.githubusercontent.com/u/50188177?v=4",
"profile": "https://jungwookim.github.io/",
"contributions": [
"code"
]
}
],
"contributorsPerLine": 7
Expand Down
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<img src="https://github.com/idahogurl/vs-code-prettier-eslint/blob/master/icon.png?raw=true" width="150">

<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->

[![All Contributors](https://img.shields.io/badge/all_contributors-3-orange.svg?style=flat-square)](#contributors-)

[![All Contributors](https://img.shields.io/badge/all_contributors-4-orange.svg?style=flat-square)](#contributors-)
<!-- ALL-CONTRIBUTORS-BADGE:END -->

# [VS Code Prettier ESLint](https://marketplace.visualstudio.com/items?itemName=rvest.vs-code-prettier-eslint)
Expand Down Expand Up @@ -82,7 +80,8 @@ 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
"vs-code-prettier-eslint.prettierLast": false, // set as "true" to run 'prettier' last not first
"vs-code-prettier-eslint.eslintConfigPath: "your-eslint-config-path"
}
```

Expand Down Expand Up @@ -162,11 +161,14 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
<table>
<tr>
<td align="center"><a href="https://github.com/idahogurl"><img src="https://secure.gravatar.com/avatar/787139c4c697cfc33cc422566a4ccf78?s=80&d=identicon?s=100" width="100px;" alt=""/><br /><sub><b>Rebecca Vest</b></sub></a><br /><a href="#question-idahogurl" title="Answering Questions">💬</a> <a href="https://github.com/idahogurl/vs-code-prettier-eslint/commits?author=idahogurl" title="Code">💻</a> <a href="https://github.com/idahogurl/vs-code-prettier-eslint/commits?author=idahogurl" title="Documentation">📖</a> <a href="#infra-idahogurl" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="https://github.com/idahogurl/vs-code-prettier-eslint/issues?q=author%3Aidahogurl" title="Bug reports">🐛</a> <a href="#ideas-idahogurl" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/idahogurl/vs-code-prettier-eslint/pulls?q=is%3Apr+reviewed-by%3Aidahogurl" title="Reviewed Pull Requests">👀</a> <a href="https://github.com/idahogurl/vs-code-prettier-eslint/commits?author=idahogurl" title="Tests">⚠️</a></td>
<td align="center"><a href="https://github.com/tbekaert"><img src="https://avatars.githubusercontent.com/u/11920484?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Thomas Bekaert</b></sub></a><br /><a href="https://github.com/idahogurl/vs-code-prettier-eslint/commits?author=tbekaert" title="Code">💻</a></td>
<td align="center"><a href="https://mattbrannon.dev/"><img src="https://avatars.githubusercontent.com/u/36570183?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Matt Brannon</b></sub></a><br /><a href="https://github.com/idahogurl/vs-code-prettier-eslint/commits?author=mattbrannon" title="Documentation">📖</a></td>
</tr>
<tbody>
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/idahogurl"><img src="https://secure.gravatar.com/avatar/787139c4c697cfc33cc422566a4ccf78?s=80&d=identicon?s=100" width="100px;" alt="Rebecca Vest"/><br /><sub><b>Rebecca Vest</b></sub></a><br /><a href="#question-idahogurl" title="Answering Questions">💬</a> <a href="https://github.com/idahogurl/vs-code-prettier-eslint/commits?author=idahogurl" title="Code">💻</a> <a href="https://github.com/idahogurl/vs-code-prettier-eslint/commits?author=idahogurl" title="Documentation">📖</a> <a href="#infra-idahogurl" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="https://github.com/idahogurl/vs-code-prettier-eslint/issues?q=author%3Aidahogurl" title="Bug reports">🐛</a> <a href="#ideas-idahogurl" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/idahogurl/vs-code-prettier-eslint/pulls?q=is%3Apr+reviewed-by%3Aidahogurl" title="Reviewed Pull Requests">👀</a> <a href="https://github.com/idahogurl/vs-code-prettier-eslint/commits?author=idahogurl" title="Tests">⚠️</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/tbekaert"><img src="https://avatars.githubusercontent.com/u/11920484?v=4?s=100" width="100px;" alt="Thomas Bekaert"/><br /><sub><b>Thomas Bekaert</b></sub></a><br /><a href="https://github.com/idahogurl/vs-code-prettier-eslint/commits?author=tbekaert" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://mattbrannon.dev/"><img src="https://avatars.githubusercontent.com/u/36570183?v=4?s=100" width="100px;" alt="Matt Brannon"/><br /><sub><b>Matt Brannon</b></sub></a><br /><a href="https://github.com/idahogurl/vs-code-prettier-eslint/commits?author=mattbrannon" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://jungwookim.github.io/"><img src="https://avatars.githubusercontent.com/u/50188177?v=4?s=100" width="100px;" alt="jungwoo"/><br /><sub><b>jungwoo</b></sub></a><br /><a href="https://github.com/idahogurl/vs-code-prettier-eslint/commits?author=jungwookim" title="Code">💻</a></td>
</tr>
</tbody>
</table>

<!-- markdownlint-restore -->
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@
"type": "boolean",
"default": false,
"description": "Run Prettier Last"
},
"vs-code-prettier-eslint.eslintConfigPath": {
"type": "string",
"default": null,
"description": "Path to ESLint config file"
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/formatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@ export default function formatText({ text, filePath, extensionConfig }) {
text,
filePath,
prettierLast: extensionConfig?.prettierLast || false,
eslintConfig: {
overrideConfigFile: extensionConfig?.eslintConfigPath || null,
},
});
}
15 changes: 15 additions & 0 deletions test/fixtures/.eslintrc.second.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
extends: './.eslintrc.js',
rules: {
'comma-dangle': [
2,
{
imports: 'never',
exports: 'never',
arrays: 'always-multiline',
objects: 'never', // <-- changed from 'always-multiline' of .eslintrc.js
functions: 'always-multiline',
},
]
}
};
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 @@ -23,6 +23,17 @@ export { options };
"
`;

exports[`Extension Test Suite setting "eslintConfigPath" uses the target .eslintrc 1`] = `
"const options = {
first: 'hello, world',
second: true,
internationalizing: true
};

export { options };
"
`;

exports[`Extension Test Suite setting "prettierLast" makes prettier run last 1`] = `
"const options = {
first: "hello, world",
Expand Down
15 changes: 15 additions & 0 deletions test/suite/extension.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,21 @@ describe('Extension Test Suite', () => {
const formatted = document.getText();
expect(formatted).toMatchSnapshot();
});

test('setting "eslintConfigPath" uses the target .eslintrc', 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('eslintConfigPath', `${basePath}/.eslintrc.second.js`, vscode.ConfigurationTarget.Global);
await vscode.commands.executeCommand('editor.action.formatDocument');
await config.update('eslintConfigPath', undefined, vscode.ConfigurationTarget.Global);

const formatted = document.getText();
expect(formatted).toMatchSnapshot();
});

afterAll(() => {
helper.clearConfig('[javascript]');
});
Expand Down