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

[Backport 2.x] [Lint] add custom stylelint rules and config #4375

Merged
merged 1 commit into from
Jun 29, 2023

Conversation

opensearch-trigger-bot[bot]
Copy link
Contributor

Backport 2e10b22 from #4290.

* [Lint] add custom stylelint rules and config

Adding `@osd/stylelint-config` and `@osd/stylelint-plugin-stylelint` packages.

These packages are utilized by OSD core and can be ran with the following:
`yarn lint:style`

Can be used to fix known non-compliant styling with the following:
`yarn lint:style --fix`

Can be used to audit untracked styling (based on defined rules) with the following:
```
export OUI_AUDIT_ENABLED=true
yarn lint:style
```

---

`@osd/stylelint-config`

Defines rules approved by UX and OSD core in JSON files and is added to OSD core.
Within this commit is defined `colors.json` and `global_selectors.json`.

`colors.json` defines a property that can be matched with a regex of a selector.
If the selector is tracked it will have an `approved` value and a list of `rejected`
values that UX knows if a value should be something.

`global_selectors.json` defines a selector that if tracked, it will have an `approved`
list of relative paths to files that can modify the global selector.

---

`@osd/stylelint-plugin-stylelint`

Creates the functionality that utilizes the JSON files within the `@osd/stylelint-config`.
Within this commit is defined `no_custom_colors` and `no_modifying_global_selectors` rules.

`no_custom_colors` checks if a property is a color property. It then utilizes a compliance
engine helper to check the `colors.json` to see if the property being modified has a compliance
rule available for the property for the specific selector and if it is not compliant.
For example, if a selector matches `button` and we are trying to apply `background-color: red`
to it. Stylelint will catch this and flag this as a known non-compliance issue since it knows
that it should `$euiColorWarning`. If we pass `--fix` the property will be updated to be
`$euiColorWarning`. If `OUI_AUDIT_ENABLED` is true it will catch all `background-color` being
modified that is not being defined explicitly in `colors.json`

`no_modifying_global_selectors` checks if a selector being modified is defined in
`global_selectors.json` to see if a selector not defined in a specific list of approved files.
For example, if a selector matches `#opensearch-dashboards-body` and it is being modified in
`src/core/public/rendering/_base.scss`. Stylelint will catch this and flag this as a
non-compliance issue. Since no other file should be modifying this selector. If we pass `--fix`
the styling will be complete removed from the non-compliant file.

---

Next steps:

* Migrate these packages to OUI
* Consider adding `yarn lint:style --fix` to the build release script here:
https://github.com/opensearch-project/opensearch-build/blob/main/scripts/default/opensearch-dashboards/build.sh#L89

Issue:
#4246

Signed-off-by: Kawika Avilla <kavilla414@gmail.com>

* fix to use find

Signed-off-by: Kawika Avilla <kavilla414@gmail.com>

* Add regex matching and OUI modification lint

Signed-off-by: Matt Provost <provomat@amazon.com>

* add changelog

Signed-off-by: Josh Romero <rmerqg@amazon.com>

* address issues

Signed-off-by: Kawika Avilla <kavilla414@gmail.com>

---------

Signed-off-by: Kawika Avilla <kavilla414@gmail.com>
Signed-off-by: Matt Provost <provomat@amazon.com>
Signed-off-by: Josh Romero <rmerqg@amazon.com>
Co-authored-by: Matt Provost <provomat@amazon.com>
Co-authored-by: Josh Romero <rmerqg@amazon.com>
(cherry picked from commit 2e10b22)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

# Conflicts:
#	CHANGELOG.md
@codecov
Copy link

codecov bot commented Jun 23, 2023

Codecov Report

Merging #4375 (fa6469a) into 2.x (716712c) will decrease coverage by 0.06%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##              2.x    #4375      +/-   ##
==========================================
- Coverage   66.40%   66.35%   -0.06%     
==========================================
  Files        3245     3245              
  Lines       62400    62400              
  Branches     9663     9663              
==========================================
- Hits        41435    41403      -32     
- Misses      18625    18652      +27     
- Partials     2340     2345       +5     
Flag Coverage Δ
Linux 66.35% <ø> (ø)
Windows ?

Flags with carried forward coverage won't be shown. Click here to find out more.

see 7 files with indirect coverage changes

@joshuarrrr
Copy link
Member

whitesource failure is expected

@ashwin-pc ashwin-pc merged commit addc22d into 2.x Jun 29, 2023
@github-actions github-actions bot deleted the backport/backport-4290-to-2.x branch June 29, 2023 17:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autocut Skip the changelog verification check on backports distinguished-contributor v2.9.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants