eslint-plugin-optional-comma-spacing

optionally require spaces before or after commas

Usage no npm install needed!

<script type="module">
  import eslintPluginOptionalCommaSpacing from 'https://cdn.skypack.dev/eslint-plugin-optional-comma-spacing';
</script>

README

Build Status

eslint-plugin-optional-comma-spacing

ESLint rule for optionally requiring spaces before or after commas.

Why Use It

You'd like to optionally require spaces before or after commas. For example if you use the standard comma-spacing this will fail

longest.id         = Math.max(longest.id        , game.gameId.length);
longest.numPlayers = Math.max(longest.numPlayers, game.numPlayers.toString().length);
longest.name       = Math.max(longest.name      , game.name.length);

I wanted those spaces before the commas to be optional hence this plugin.

This is just a clone of the standard comma-spacing rule. The difference is where as the comma-spacing rule only has before: true | false and after: true | false this one has before: undefined | true | false and after: undefined | true | false. Both rules default to undefined so you can therefore do this

'eslint-plugin-optional-comma-space': [2, {'after': true}],

Which will require spaces after a comma but before a comma they are optional.

Further Reading