diff --git a/.all-contributorsrc b/.all-contributorsrc
index d1b20c2..49119ba 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -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
diff --git a/README.md b/README.md
index 79c01c7..1ac0e92 100644
--- a/README.md
+++ b/README.md
@@ -1,9 +1,7 @@
-
-[](#contributors-)
-
+[](#contributors-)
# [VS Code Prettier ESLint](https://marketplace.visualstudio.com/items?itemName=rvest.vs-code-prettier-eslint)
@@ -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"
}
```
@@ -162,11 +161,14 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
diff --git a/package.json b/package.json
index 1840430..bb978f4 100644
--- a/package.json
+++ b/package.json
@@ -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"
}
}
}
diff --git a/src/formatter.js b/src/formatter.js
index b570593..60b21d4 100644
--- a/src/formatter.js
+++ b/src/formatter.js
@@ -5,5 +5,8 @@ export default function formatText({ text, filePath, extensionConfig }) {
text,
filePath,
prettierLast: extensionConfig?.prettierLast || false,
+ eslintConfig: {
+ overrideConfigFile: extensionConfig?.eslintConfigPath || null,
+ },
});
}
diff --git a/test/fixtures/.eslintrc.second.js b/test/fixtures/.eslintrc.second.js
new file mode 100644
index 0000000..5e6abbb
--- /dev/null
+++ b/test/fixtures/.eslintrc.second.js
@@ -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',
+ },
+ ]
+ }
+};
diff --git a/test/suite/__snapshots__/extension.test.js.snap b/test/suite/__snapshots__/extension.test.js.snap
index a12ef9f..91717c7 100644
--- a/test/suite/__snapshots__/extension.test.js.snap
+++ b/test/suite/__snapshots__/extension.test.js.snap
@@ -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",
diff --git a/test/suite/extension.test.js b/test/suite/extension.test.js
index 97a9c55..0131a12 100644
--- a/test/suite/extension.test.js
+++ b/test/suite/extension.test.js
@@ -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]');
});