Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prettier configuration does not take effect #7864

Closed
pengdongliang opened this issue Sep 2, 2023 · 6 comments
Closed

Prettier configuration does not take effect #7864

pengdongliang opened this issue Sep 2, 2023 · 6 comments

Comments

@pengdongliang
Copy link

Description

How to Change Prettier Configuration in Custom Env?

Specifications

  • Bit version: 0.2.24
  • Node version: 18.12.1
  • npm / yarn version: 8.19.2
  • Platform:
  • Bit compiler (include version):
  • Bit tester (include version):

Context and additional information

  1. I configured a prettier in the custom env, but it doesn't seem to work. When I run 'bit tag', I will report a syntax error.
  2. It seems that the version of the custom prettier does not take effect either
// env/config/prettier.config.js

module.exports = {
  semi: false,
}
// env.bit-env.ts

import prettier from 'prettier' // v2.8.8

export class AdminEnv extends ReactEnv implements DependenciesEnv {
  protected prettierConfigPath = require.resolve('./config/prettier.config.js')

  formatter() {
    return PrettierFormatter.from({
      configPath: this.prettierConfigPath,
      prettier,
    })
  }

  workspaceConfig(): ConfigWriterList {
    return ConfigWriterList.from([
      PrettierConfigWriter.from({
        configPath: this.prettierConfigPath,
      }),
    ]}
  }
$ bit tag --message initial

66:2   error  Replace `` with `;`
                         prettier/prettier

$ bit envs get envs/admin-env --services teambit.defender/formatter

Environment: teambit.envs/env
teambit.defender/formatter

configured formatter: prettier-formatter (Prettier @ 2.3.2)
formatter config:
{
  "trailingComma": "es5",
  "tabWidth": 2,
  "singleQuote": true
}
@GiladShoham
Copy link
Member

What you see in the bit env get you attached is the config of the env of the env (which is teambit.envs/env)
The changes you do in your custom env will affect components that uses this env and not the env itself.
You can run the bit env get on one off the components that uses the env to see it

@pengdongliang
Copy link
Author

您在附加的位环境中看到的是环境的环境配置(即 teambit.envs/env)。 您在自定义环境中所做的更改将影响使用此环境的组件,而不是环境本身。 您可以在使用 env 的组件之一上运行 bit env get 来查看它

bit tag --message initial

66:2   error  Replace `␍` with `;`  prettier/prettier

This error is very strange. I can pass with 'bit lint', but if I use 'bit build' or 'bit tag', an error will be reported. The eslint I configured removes the trailing part number and uses single quotes.

2023-09-03_021059

@benjgil
Copy link
Contributor

benjgil commented Sep 4, 2023

Hi
Did you actually run bit format after configuring prettier via the env?
If you didnt then there's no point at which the formatter was actually run on your code...

Also, if you want formatting to run automatically during the build pipeline, you'll need to add the formatter task, with your config, to the build() pipeline in your custom env.

@pengdongliang
Copy link
Author

pengdongliang commented Sep 10, 2023

您好,您通过环境配置 Prettier 后 实际上运行了吗? 如果您没有这样做,那么格式化程序就没有实际在您的代码上运行的意义......bit format

此外,如果您希望格式化在构建管道期间自动运行,则需要将格式化程序任务和您的配置添加到自定义环境中的 build() 管道中。

Thank you for your answer, I found the cause, but I can't solve it well, because eslint's 'rules: { prettier/prettier: { "error" } }', I tried a lot of methods, there will still be a conflict between eslint and prettier, I can only turn off this check to pass bit build.
Running 'bit format' and 'bit lint' can be run through, that is, the eslintTask in the build will fail after running 'bit build', and eslint in my webstorm is normal.

@GiladShoham
Copy link
Member

when running bit format then bit lint does bit lint fails?

@itaymendel
Copy link
Contributor

formatting should not run during build, it's a workspace command. this should happen before you version your changes.

with recent updates, and bit ws-config write you can just have your IDE handle your formatting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants