Skip to content

Conversation

zojize
Copy link
Contributor

@zojize zojize commented Dec 28, 2024

Description

This PR implements the keep-aligned command, it accepts a list of symbols to align and an optional * at the end to indicate a repeating pattern

Example

// @keep-aligned , , ,
export const matrix = [
  1    , 0    , 0 ,
  0.866, -0.5 , 0 ,
  0.5  , 0.866, 42,
]

// alternatively
// @keep-aligned* ,
export const matrix = [
  1    , 0    , 0 ,
  0.866, -0.5 , 0 ,
  0.5  , 0.866, 42,
]

Linked Issues

closes #31

Caveats and Possible Enhancements

This rule does NOT work well with other spacing rules, namely style/no-multi-spaces, style/comma-spacing, antfu/consistent-list-newline were disabled for the example in the markdown file to work. I don't know if it's possible for this rule to disable related spacing rules on-demand, but currently, the best solution is to disable specific eslint rules for the range/line affected by this command.

Currently which symbols to align by must be declared for this command to function. It might be possible to infer the alignment symbols based on the current alignment.

Copy link

netlify bot commented Dec 28, 2024

Deploy Preview for resonant-bonbon-a310e6 ready!

Name Link
🔨 Latest commit 22bdf35
🔍 Latest deploy log https://app.netlify.com/sites/resonant-bonbon-a310e6/deploys/67746c568b3c7e0008c453de
😎 Deploy Preview https://deploy-preview-32--resonant-bonbon-a310e6.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

eslint.config.js Outdated
'style/max-statements-per-line': 'off',
'style/no-multi-spaces': 'off',
'style/comma-spacing': 'off',
'antfu/consistent-list-newline': 'off',
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't disable them globally to support this optional command.

Instead, we could document and tell users to disable these rules with inline comments.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the only way I was able to get past the linter hooks, I tried disabling the specific markdown file but it didn't seem to work, not sure why exactly. I definitely agree it should be mentioned in the docs, I will make an update on this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the docs and edited the ESLint file removing the global rules. I ended up having to ignore the markdown file entirely because even if you disable the right rules, the example I provided at the end to demonstrate the ESlint ignore usage will complain about unused eslint-disable directive, which I have not idea how to suppress...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just found out about eslint-skip 😂. It should work now without ignoring the file or disabling global eslint rules.

@zojize zojize requested a review from antfu December 31, 2024 22:15
@antfu antfu merged commit 45a5e04 into antfu:main Jan 9, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] keep-aligned

2 participants