Skip to content

Commit

Permalink
fix: avoid Object.assign
Browse files Browse the repository at this point in the history
  • Loading branch information
filiptammergard committed Nov 3, 2023
1 parent 43dc4ae commit 663a31f
Showing 1 changed file with 28 additions and 35 deletions.
63 changes: 28 additions & 35 deletions eslint-plugin-prettier.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,25 +74,12 @@ function reportDifference(context, difference) {
// Module Definition
// ------------------------------------------------------------------------------

/**
* @type {Plugin}
*/
// Type hint configs key as non-nullable to avoid type-checking errors in when
// assigning to eslintPluginPrettier.config below
/** @type {Plugin & {configs: NonNullable<Plugin['configs']>}} */
const eslintPluginPrettier = {
meta: {
name,
version,
},
configs: {
recommended: {
extends: ['prettier'],
plugins: ['prettier'],
rules: {
'prettier/prettier': 'error',
'arrow-body-style': 'off',
'prefer-arrow-callback': 'off',
},
},
},
meta: { name, version },
configs: {},
rules: {
prettier: {
meta: {
Expand Down Expand Up @@ -229,24 +216,30 @@ const eslintPluginPrettier = {
},
};

/**
* @type {Plugin}
*/
const eslintPluginPrettierWithFlatConfig = {
...eslintPluginPrettier,
configs: {
...eslintPluginPrettier.configs,
'recommended-flat': {
plugins: {
prettier: eslintPluginPrettier,
},
rules: {
'prettier/prettier': 'error',
'arrow-body-style': 'off',
'prefer-arrow-callback': 'off',
},
// Assign configs after initial plugin configuration, as flat configs
// require referencing the original plugin that contains the rules.
eslintPluginPrettier.configs = {
recommended: {
extends: 'prettier',
plugins: ['prettier'],
rules: {
'prettier/prettier': 'error',
'arrow-body-style': 'off',
'prefer-arrow-callback': 'off',
},
},
['recommended-flat']: {
// In the flat config, don't extend from the eslint-config-prettier ruleset.
// The consumer should deal with extending from eslint-config-prettier themselves.
plugins: {
prettier: eslintPluginPrettier,
},
rules: {
'prettier/prettier': 'error',
'arrow-body-style': 'off',
'prefer-arrow-callback': 'off',
},
},
};

module.exports = eslintPluginPrettierWithFlatConfig;
module.exports = eslintPluginPrettier;

0 comments on commit 663a31f

Please sign in to comment.