diff --git a/apps/remix-ide/src/app/plugins/code-format.ts b/apps/remix-ide/src/app/plugins/code-format.ts index 0a01e08769..45b2191d2d 100644 --- a/apps/remix-ide/src/app/plugins/code-format.ts +++ b/apps/remix-ide/src/app/plugins/code-format.ts @@ -28,6 +28,10 @@ export class CodeFormat extends Plugin { const content = await this.call('fileManager', 'readFile', file) if (!content) return let parserName = '' + // parse TOML file + // parse YAML file + // parse JSON file + let options: Options = { } switch (path.extname(file)) { @@ -58,6 +62,24 @@ export class CodeFormat extends Plugin { parserName = 'json' break } + const possibleFileNames = [ + '.prettierrc', + '.prettierrc.json', + '.prettierrc.yaml', + '.prettierrc.yml', + '.prettierrc.toml', + 'prettier.js', + 'prettier.cjs', + 'prettier.config.js', + 'prettier.config.cjs', + 'prettier.config.mjs', + 'prettier.config.ts', + ] + // find first file that exists + const prettierConfigFile = possibleFileNames.find(async fileName => await this.call('fileManager', 'exists', fileName)) + + console.log(prettierConfigFile) + const result = prettier.format(content, { plugins: [sol as any, ts, babel, espree], parser: parserName, diff --git a/package.json b/package.json index f25adea484..819e5ddabd 100644 --- a/package.json +++ b/package.json @@ -219,12 +219,14 @@ "string-similarity": "^4.0.4", "swarmgw": "^0.3.1", "time-stamp": "^2.2.0", + "toml": "^3.0.0", "tree-kill": "^1.2.2", "ts-loader": "^9.2.6", "tslib": "^2.3.0", "web3": "^1.7.5", "winston": "^3.3.3", - "ws": "^7.3.0" + "ws": "^7.3.0", + "yaml": "^2.1.3" }, "devDependencies": { "@babel/core": "^7.4.5", diff --git a/yarn.lock b/yarn.lock index 8000846047..6b679b1add 100644 --- a/yarn.lock +++ b/yarn.lock @@ -22819,6 +22819,11 @@ toidentifier@1.0.0: resolved "https://registry.yarnpkg.com/toidentifier/-/toidentifier-1.0.0.tgz#7e1be3470f1e77948bc43d94a3c8f4d7752ba553" integrity sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw== +toml@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/toml/-/toml-3.0.0.tgz#342160f1af1904ec9d204d03a5d61222d762c5ee" + integrity sha512-y/mWCZinnvxjTKYhJ+pYxwD0mRLVvOtdS2Awbgxln6iEnt4rk0yBxeSBHkGJcPucRiG0e55mwWp+g/05rsrd6w== + touch@^3.1.0: version "3.1.0" resolved "https://registry.yarnpkg.com/touch/-/touch-3.1.0.tgz#fe365f5f75ec9ed4e56825e0bb76d24ab74af83b" @@ -24793,6 +24798,11 @@ yaml@^1.10.0, yaml@^1.10.2, yaml@^1.7.2: resolved "https://registry.yarnpkg.com/yaml/-/yaml-1.10.2.tgz#2301c5ffbf12b467de8da2333a459e29e7920e4b" integrity sha512-r3vXyErRCYJ7wg28yvBY5VSoAF8ZvlcW9/BwUzEtUsjvX/DKs24dIkuwjtuprwJJHsbyUbLApepYTR1BN4uHrg== +yaml@^2.1.3: + version "2.1.3" + resolved "https://registry.yarnpkg.com/yaml/-/yaml-2.1.3.tgz#9b3a4c8aff9821b696275c79a8bee8399d945207" + integrity sha512-AacA8nRULjKMX2DvWvOAdBZMOfQlypSFkjcOcu9FalllIDJ1kvlREzcdIZmidQUqqeMv7jorHjq2HlLv/+c2lg== + yargs-parser@20.0.0, yargs-parser@20.x: version "20.0.0" resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-20.0.0.tgz#c65a1daaa977ad63cebdd52159147b789a4e19a9"