From 385447f99a7694e14490504c17861c4f9c524560 Mon Sep 17 00:00:00 2001 From: Jungwoo Kim Date: Mon, 24 Apr 2023 12:10:25 +0900 Subject: [PATCH 1/7] add eslintConfigPath --- README.md | 3 ++- package.json | 5 +++++ src/formatter.js | 1 + test/fixtures/.eslintrc.second.js | 15 +++++++++++++++ test/suite/__snapshots__/extension.test.js.snap | 11 +++++++++++ test/suite/extension.test.js | 15 +++++++++++++++ 6 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/.eslintrc.second.js diff --git a/README.md b/README.md index 79c01c7..1541d93 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,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" } ``` 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..ef5e708 100644 --- a/src/formatter.js +++ b/src/formatter.js @@ -5,5 +5,6 @@ export default function formatText({ text, filePath, extensionConfig }) { text, filePath, prettierLast: extensionConfig?.prettierLast || false, + eslintConfig: extensionConfig?.eslintConfigPath, }); } diff --git a/test/fixtures/.eslintrc.second.js b/test/fixtures/.eslintrc.second.js new file mode 100644 index 0000000..65851be --- /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', + functions: 'always-multiline', + }, + ] + } +}; diff --git a/test/suite/__snapshots__/extension.test.js.snap b/test/suite/__snapshots__/extension.test.js.snap index a12ef9f..27dff63 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]'); }); From c062ad6decb442cfd2722d8d4e84d5b8f0b8c572 Mon Sep 17 00:00:00 2001 From: Jungwoo Kim Date: Mon, 24 Apr 2023 15:48:24 +0900 Subject: [PATCH 2/7] fix typo --- test/fixtures/.eslintrc.second.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/fixtures/.eslintrc.second.js b/test/fixtures/.eslintrc.second.js index 65851be..a9d2a4a 100644 --- a/test/fixtures/.eslintrc.second.js +++ b/test/fixtures/.eslintrc.second.js @@ -1,5 +1,5 @@ module.exports = { - extends: './eslintrc.js', + extends: './.eslintrc.js', rules: { 'comma-dangle': [ 2, From a5670223befaa21d35181093d5f7639cc635db5f Mon Sep 17 00:00:00 2001 From: Jungwoo Kim Date: Mon, 24 Apr 2023 17:44:39 +0900 Subject: [PATCH 3/7] apply snapshot --- test/suite/__snapshots__/extension.test.js.snap | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/suite/__snapshots__/extension.test.js.snap b/test/suite/__snapshots__/extension.test.js.snap index 27dff63..6fdc571 100644 --- a/test/suite/__snapshots__/extension.test.js.snap +++ b/test/suite/__snapshots__/extension.test.js.snap @@ -27,7 +27,7 @@ exports[`Extension Test Suite setting "eslintConfigPath" uses the target .eslint "const options = { first: "hello, world", second: true, - internationalizing: true, + internationalizing: true } export { options } From e6bc083fdbf3189098b5a70f15598883dfc3cc69 Mon Sep 17 00:00:00 2001 From: Jungwoo Kim Date: Mon, 24 Apr 2023 17:54:11 +0900 Subject: [PATCH 4/7] update snapshot --- test/suite/__snapshots__/extension.test.js.snap | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/suite/__snapshots__/extension.test.js.snap b/test/suite/__snapshots__/extension.test.js.snap index 6fdc571..27dff63 100644 --- a/test/suite/__snapshots__/extension.test.js.snap +++ b/test/suite/__snapshots__/extension.test.js.snap @@ -27,7 +27,7 @@ exports[`Extension Test Suite setting "eslintConfigPath" uses the target .eslint "const options = { first: "hello, world", second: true, - internationalizing: true + internationalizing: true, } export { options } From b4ff90f2b4e3ab3e0501d19f648a39d6c5b1f2a7 Mon Sep 17 00:00:00 2001 From: Jungwoo Kim Date: Mon, 24 Apr 2023 19:34:33 +0900 Subject: [PATCH 5/7] use object, not path --- src/formatter.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/formatter.js b/src/formatter.js index ef5e708..a97d2c8 100644 --- a/src/formatter.js +++ b/src/formatter.js @@ -1,10 +1,11 @@ import format from 'prettier-eslint'; +import fs from 'fs'; export default function formatText({ text, filePath, extensionConfig }) { return format({ text, filePath, prettierLast: extensionConfig?.prettierLast || false, - eslintConfig: extensionConfig?.eslintConfigPath, + eslintConfig: extensionConfig?.eslintConfigPath ? JSON.parse(fs.readFileSync(extensionConfig?.eslintConfigPath)) : null }); } From 22f7edfffcdeb14b75b9d20360da690467820677 Mon Sep 17 00:00:00 2001 From: jungwookim Date: Sun, 4 Jun 2023 16:04:48 +0900 Subject: [PATCH 6/7] pass eslintConfig bug fix --- src/formatter.js | 5 +++-- test/fixtures/.eslintrc.second.js | 2 +- test/suite/__snapshots__/extension.test.js.snap | 10 +++++----- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/formatter.js b/src/formatter.js index a97d2c8..60b21d4 100644 --- a/src/formatter.js +++ b/src/formatter.js @@ -1,11 +1,12 @@ import format from 'prettier-eslint'; -import fs from 'fs'; export default function formatText({ text, filePath, extensionConfig }) { return format({ text, filePath, prettierLast: extensionConfig?.prettierLast || false, - eslintConfig: extensionConfig?.eslintConfigPath ? JSON.parse(fs.readFileSync(extensionConfig?.eslintConfigPath)) : null + eslintConfig: { + overrideConfigFile: extensionConfig?.eslintConfigPath || null, + }, }); } diff --git a/test/fixtures/.eslintrc.second.js b/test/fixtures/.eslintrc.second.js index a9d2a4a..5e6abbb 100644 --- a/test/fixtures/.eslintrc.second.js +++ b/test/fixtures/.eslintrc.second.js @@ -7,7 +7,7 @@ module.exports = { imports: 'never', exports: 'never', arrays: 'always-multiline', - objects: 'never', + 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 27dff63..91717c7 100644 --- a/test/suite/__snapshots__/extension.test.js.snap +++ b/test/suite/__snapshots__/extension.test.js.snap @@ -25,12 +25,12 @@ export { options }; exports[`Extension Test Suite setting "eslintConfigPath" uses the target .eslintrc 1`] = ` "const options = { - first: "hello, world", - second: true, - internationalizing: true, -} + first: 'hello, world', + second: true, + internationalizing: true +}; -export { options } +export { options }; " `; From 74e9558063e602cf9d75fcf00502be93b51393f5 Mon Sep 17 00:00:00 2001 From: jungwookim Date: Tue, 6 Jun 2023 11:32:45 +0900 Subject: [PATCH 7/7] Docs: Add @jungwookim as a contributor --- .all-contributorsrc | 9 +++++++++ README.md | 17 +++++++++-------- 2 files changed, 18 insertions(+), 8 deletions(-) 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 1541d93..1ac0e92 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,7 @@ - -[![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-) # [VS Code Prettier ESLint](https://marketplace.visualstudio.com/items?itemName=rvest.vs-code-prettier-eslint) @@ -163,11 +161,14 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d - - - - - + + + + + + + +

Rebecca Vest

💬 💻 📖 🚇 🐛 🤔 👀 ⚠️

Thomas Bekaert

💻

Matt Brannon

📖
Rebecca Vest
Rebecca Vest

💬 💻 📖 🚇 🐛 🤔 👀 ⚠️
Thomas Bekaert
Thomas Bekaert

💻
Matt Brannon
Matt Brannon

📖
jungwoo
jungwoo

💻