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

Give rules access to settings #279

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open

Give rules access to settings #279

wants to merge 15 commits into from

Conversation

jablko
Copy link
Contributor

@jablko jablko commented Feb 17, 2022

Initial checklist

  • I read the support docs
  • I read the contributing guide
  • I agree to follow the code of conduct
  • I searched issues and couldn’t find anything (or linked relevant results below)
  • If applicable, I’ve added docs and tests

Description of changes

I'm interested in working on this: Giving rules access to settings.

Also, some rules might need access to the fileSet too? but from what I could gather, while settings is accessible via this (processor: this.data().settings), fileSet isn't? Consequently I've appended it to the rule arguments, symmetric with how the other (options) attacher parameter is appended to the rule arguments, roughly.

Fixes #263 (comment)

@github-actions github-actions bot added the 👋 phase/new Post is being triaged automatically label Feb 17, 2022
@github-actions

This comment has been minimized.

@jablko jablko force-pushed the patch-1 branch 4 times, most recently from ca0bfba to 9f2c248 Compare February 17, 2022 22:36
@codecov-commenter

This comment was marked as resolved.

@jablko jablko force-pushed the patch-1 branch 2 times, most recently from d816196 to f5ddf64 Compare February 17, 2022 23:03
@github-actions github-actions bot added 🤞 phase/open Post is being triaged manually and removed 👋 phase/new Post is being triaged automatically labels Feb 19, 2022
@jablko jablko force-pushed the patch-1 branch 8 times, most recently from deed8ce to ef344b4 Compare February 20, 2022 18:18
Copy link
Member

@ChristianMurphy ChristianMurphy left a comment

Choose a reason for hiding this comment

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

Thanks @jablko!
It's good to see #279 moving forward, thanks for taking time to look into it.

A general note, there seem to be some changes which, at first blush appear to be unrelated mixed in here.
Some documentation changes, and (semver) major changes to how settings directly passed are handled.
Are those intentional? Could you expand a bit on how they tie into this PR and what the goal/intention with the additional changes is?

so, some rules might need access to the fileSet too

Could you expand on this?
In general Unified/remark/remark-lint acts on a single file at a time.
There has been some thoughts on a higher level tool which would handle multiple files unifiedjs/ideas#11 (comment), but that would likely live at a higher level of abstraction?

packages/remark-lint-blockquote-indentation/readme.md Outdated Show resolved Hide resolved
@@ -40,32 +40,32 @@
* @copyright 2015 Titus Wormer
* @license MIT
* @example
* {"setting": "*", "name": "ok.md"}
* {"settings": {"emphasis": "*"}, "name": "ok.md"}
Copy link
Member

Choose a reason for hiding this comment

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

this appears to suggest a breaking change?
That all configuration would need to be updated to this format?
Is that accurate?

@@ -135,14 +135,10 @@ a value of `2` can be defined here.

##### `ok.md`

When configured with `2`.
Copy link
Member

Choose a reason for hiding this comment

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

again, I'm a bit confused.
These changes appear to be unrelated to the settings, and it's unclear what these changes fix/improve.

@@ -77,7 +77,7 @@ export function rule(filePath) {

while (++index < examples.length) {
const lines = examples[index].split('\n')
/** @type {{name: string, label?: 'input'|'output', setting?: unknown, positionless?: boolean, gfm?: boolean}} */
/** @type {{name: string, label?: 'input'|'output', settings?: unknown, setting?: unknown, positionless?: boolean, gfm?: boolean}} */
Copy link
Member

Choose a reason for hiding this comment

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

this seems like a typo, defining settings twice

Copy link
Contributor Author

@jablko jablko Feb 20, 2022

Choose a reason for hiding this comment

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

settings is the processor.use({settings}) argument vs. setting is the processor.use(rule, setting) argument.

@jablko
Copy link
Contributor Author

jablko commented Feb 20, 2022

@ChristianMurphy Thank you for the encouragement!

I started out aiming to give rules access to settings --- but to actually fix #263 (comment), I additionally made the remark-lint-emphasis-marker and remark-lint-strong-marker options default to settings.emphasis and settings.strong, respectively:

if (!option) {
const settings = this.data('settings')
option = (settings && settings.emphasis) || 'consistent'
}

I've now added a commit to update those docs. 👍

@jablko
Copy link
Contributor Author

jablko commented Feb 20, 2022

unified-engine passes options and fileSet to the attacher function. Plugins use it. With this change, rules can too?

.github/workflows/main.yml Outdated Show resolved Hide resolved
@jablko
Copy link
Contributor Author

jablko commented Feb 21, 2022

I've added a commit to make the remaining rules' options default to their respective settings.

@jablko jablko force-pushed the patch-1 branch 2 times, most recently from c6a986f to 20685cf Compare February 22, 2022 16:46
@wooorm
Copy link
Member

wooorm commented Mar 24, 2022

@jablko How’s it going here? Can you let me know if you need help or if there’s anything in particular to review?

@jablko jablko force-pushed the patch-1 branch 5 times, most recently from ad97cc3 to c59a20a Compare March 28, 2022 15:25
Copy link
Contributor Author

@jablko jablko left a comment

Choose a reason for hiding this comment

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

Thanks for the helpful and detailed feedback!

// recommended preset, but if we’d prefer something else, it can be
// reconfigured:
settings: {listItemIndent: 'one'}
})
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've edited the prose:

settings.listItemIndent is set to tab in the recommended preset, but you can change it if you’d prefer something else:


* Pass a severity, options, or both to the rules themselves.
This affects each rule individually and takes highest precedence.
* Some rules correspond to settings that are shared among all remark plugins --- particularly [`remark-stringify`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#options).
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've added shared settings docs to the Configure section.

to always use fenced code.

## Examples

##### `ok.md`

When configured with `'indented'`.
When [`settings.fences`](https://github.com/remarkjs/remark-lint#configure) is `false` and the rule is not configured.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

  • In each readme I've linked to the monorepo Configure section.

Comment on lines +290 to +305
| Setting | Rule |
| - | - |
| [`settings.bullet`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionsbullet) | [`remark-lint-unordered-list-marker-style`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-unordered-list-marker-style) |
| [`settings.bulletOrdered`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionsbulletordered) | [`remark-lint-ordered-list-marker-style`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-ordered-list-marker-style) |
| [`settings.closeAtx`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionscloseatx) | [`remark-lint-heading-style`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-heading-style) |
| [`settings.emphasis`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionsemphasis) | [`remark-lint-emphasis-marker`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-emphasis-marker) |
| [`settings.fence`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionsfence) | [`remark-lint-fenced-code-marker`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-fenced-code-marker) |
| [`settings.fences`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionsfences) | [`remark-lint-code-block-style`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-code-block-style) |
| [`settings.incrementListMarker`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionsincrementlistmarker) | [`remark-lint-ordered-list-marker-value`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-ordered-list-marker-value) |
| [`settings.listItemIndent`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionslistitemindent) | [`remark-lint-list-item-indent`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-list-item-indent) |
| [`settings.quote`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionsquote) | [`remark-lint-link-title-style`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-link-title-style) |
| [`settings.rule`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionsrule) | [`remark-lint-rule-style`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-rule-style) |
| [`settings.ruleRepetition`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionsrulerepetition) | [`remark-lint-rule-style`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-rule-style) |
| [`settings.ruleSpaces`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionsrulespaces) | [`remark-lint-rule-style`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-rule-style) |
| [`settings.setext`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionssetext) | [`remark-lint-heading-style`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-heading-style) |
| [`settings.strong`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionsstrong) | [`remark-lint-strong-marker`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-strong-marker) |
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've added a table to the Configure section, listing the settings that also affect lint rules.

Comment on lines +320 to +323
> 🧑‍🏫 **Info**: remark lint rules *check* markdown.
> [`remark-stringify`][remark-stringify] *formats* markdown.
> They behave consistently when you change shared settings that they both understand, but not if you pass options to rules individually.
> Passing options to rules individually doesn't affect [`remark-stringify`][remark-stringify] or vice versa.
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've added the trade-offs between rules' options and shared settings to the Configure section, and called out the synchronization problem.

@@ -141,24 +138,24 @@ This preset configures [`remark-lint`][mono] with the following rules:
| [`remark-lint-maximum-line-length`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-maximum-line-length) | `80` |
| [`remark-lint-no-shell-dollars`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-no-shell-dollars) | |
| [`remark-lint-hard-break-spaces`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-hard-break-spaces) | |
| [`remark-lint-heading-style`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-heading-style) | `'atx'` |
| [`remark-lint-heading-style`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-heading-style) | [`settings.setext`](https://github.com/remarkjs/remark-lint#configure) is `false` |
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've distinguished between rules' options and shared settings in the presets' readmes.

const {settings, rawOptions} = JSON.parse(configuration)
const fixtures = tests[configuration]

// Don't show the same test for both shared settings and rules' options.
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've hidden repetitious examples from the readmes:
  • All of the existing tests are retained.
  • Each readme has the same number of examples as it does now.

@JounQin
Copy link
Member

JounQin commented Jul 26, 2022

Are we moving on this?

cc @wooorm

@wooorm
Copy link
Member

wooorm commented Jul 27, 2022

It’s been a while!

@jablko Was this done? Ready for another review? Anything in particular I can help with?

@romgere
Copy link

romgere commented Mar 17, 2023

Any update on this 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🗄 area/interface This affects the public interface 🤞 phase/open Post is being triaged manually
Development

Successfully merging this pull request may close these issues.

read settings config for rules like remark-lint-strong-marker
6 participants