Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.

give option to avoid reformatting code or at least respect prettier rc in project root #40

Open
emahuni opened this issue Aug 28, 2022 · 6 comments
Labels
issue: feature request Issue suggesting a new feature

Comments

@emahuni
Copy link

emahuni commented Aug 28, 2022

There are coding conventions that teams follow that this mod is assuming as THE standard. However, it should be to the engineer what to transform. So give them the option to disable reformatting of code by both disabling prettier completely and/or using prettier .prettierrc.js file... in project root.

I had to fork and comment out the line that formats the code.

@derrickmehaffy
Copy link
Member

Can you be specific about which part you are referring to and what you had to comment out?

@emahuni
Copy link
Author

emahuni commented Aug 30, 2022

So sorry for being so vague, I modified these 2 lines with as minimum impact as possible (though this makes the formatFile function redundant, I didn't want to break anything and then fix it):

path, fileContent

so from this:

const formatFile = async (path) => {
  try {
    const fileContent = await readFile(path, 'utf-8');
    // Format the code with prettier
    return writeFile(
      path, prettier.format(fileContent, {
         filepath: path,
       })
    );
  } catch (error) {
    logger.warn(`Failed to format code, check ${path}`);
  }
};

to this:

const formatFile = async (path) => {
  try {
    const fileContent = await readFile(path, 'utf-8');
    // Format the code with prettier
    return writeFile(
      path, fileContent
//       prettier.format(fileContent, {
//         filepath: path,
//       })
    );
  } catch (error) {
    logger.warn(`Failed to format code, check ${path}`);
  }
};

This was causing a lot of undesired results. We tried to use an rc file and everything and noticed that it's not respecting any of that.

@markkaylor
Copy link
Contributor

Good point. I'm starting to think we should probably just remove the formatting and leave that up to the end user. I think the format function is only called in one spot so the clean up should be pretty quick.

@derrickmehaffy
Copy link
Member

Good point. I'm starting to think we should probably just remove the formatting and leave that up to the end user. I think the format function is only called in one spot so the clean up should be pretty quick.

@emahuni are you willing to submit a PR to remove the code formatting? If so I can review it and merge it in as I agree with Mark here that we should just get rid of it.

@emahuni
Copy link
Author

emahuni commented Sep 2, 2022

I have created the pull request

@emahuni
Copy link
Author

emahuni commented Sep 2, 2022

I didn't remove the prettierrc file, not sure what it is used for, since any edits didn't seem to affect the code formatting I was after. You are free to remove any changes to it or it altogether if you understand why it's there and if it was supposed to work in tandem with the code formatting we are removing.

@derrickmehaffy derrickmehaffy added the issue: feature request Issue suggesting a new feature label Oct 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
issue: feature request Issue suggesting a new feature
Projects
None yet
Development

No branches or pull requests

3 participants