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 compatibility for JS/TS (eslint-config-prettier) #615

Open
3 tasks done
fregante opened this issue Sep 24, 2024 · 6 comments
Open
3 tasks done

Prettier compatibility for JS/TS (eslint-config-prettier) #615

fregante opened this issue Sep 24, 2024 · 6 comments
Labels
enhancement New feature or request

Comments

@fregante
Copy link

Clear and concise description of the problem

I'd like to use Prettier (externally) and this config for everything else. The suggestion is generally to use either stylistic or prettier, but not both. The problem is that stylistic has extra linting rules that Prettier doesn't concern itself with.

We have eslint-config-prettier for this purpose but I don’t think it works when plugins are renamed.

Suggested solution

import antfu from '@antfu/eslint-config'

export default antfu({
	prettierCompat: true,
})

Alternative

I think the alternative is

import antfu from '@antfu/eslint-config'
import eslintConfigPrettier from 'eslint-config-prettier'

export default [
	...antfu()
		.renamePlugins({
		ts: '@typescript-eslint',
		yaml: 'yml',
		node: 'n'
		// …
	}),
	eslintConfigPrettier,
]

with the drawbacks:

  • having to manually specify and maintain the renames list
  • losing the advantages of the rename

Additional context

No response

Validations

@fregante fregante added the enhancement New feature or request label Sep 24, 2024
@fregante
Copy link
Author

An alternative solution is to find and disable all conflicting rules. In my case, for now, it's:

export default antfu({
	rules: {
		'style/arrow-parens': 'off',
		'style/object-curly-spacing': 'off',
		'style/brace-style': 'off',
		'style/indent': 'off',
		'style/operator-linebreak': 'off',
		'style/quote-props': 'off',
		'svelte/indent': 'off',
	},
});

Which is not terrible, but also it's likely that new contributors will find more issues and won't know how to deal with them. eslint-config-prettier already exists as a solution to this and it would be great to be able to use it.

@antfu
Copy link
Owner

antfu commented Oct 5, 2024

Maybe you can use https://www.npmjs.com/package/eslint-flat-config-utils (the one this config also uses) with eslintConfigPrettier to rename the disable rules back instead?

@fregante
Copy link
Author

fregante commented Oct 5, 2024

After:

I think I will be able to use this:

import antfu from '@antfu/eslint-config'
import prettier from 'eslint-config-prettier'
import { composer } from 'eslint-flat-config-utils'

export default antfu().overrideRules(composer(prettier)).renamePlugins({
	'@typescript-eslint': 'ts',
	'@stylistic': 'style',
});

I wonder if eslint-flat-config-utils should just (optionally?) preserve/reapply the renames automatically, so that I can use:

import antfu from '@antfu/eslint-config'
import prettier from 'eslint-config-prettier'

export default antfu().overrideRules(prettier);

This would be very reasonable, short of including eslint-config-prettier in this config via prettierCompat: true

@antfu
Copy link
Owner

antfu commented Oct 21, 2024

I wonder if eslint-flat-config-utils should just (optionally?) preserve/reapply the renames automatically, so that I can use:

I think it should be doing that already - if not I'd consider it a bug

@fregante

This comment was marked as off-topic.

@fregante
Copy link
Author

fregante commented Oct 21, 2024

It seems that you're right. Let's wait for this PR to be merged:

and then this issue can be fixed by just documenting it in the readme, e.g.

## Prettier 

If you're using prettier outside eslint, you can disable the config via etc:

```js
import antfu from '@antfu/eslint-config'
import prettierConflicts from 'eslint-config-prettier'

export default antfu({
	rules: {
		'some-rule': 'off'
	}
}, prettierConflicts);
```

I found a small exception:

  • antfu/consistent-chaining

It conflicts with prettier, but it's not part of stylistic. I wonder if they will accept it in eslint-config-prettier

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants