Skip to content

feat: add stylelint-plugin#115

Merged
valerybugakov merged 4 commits intomainfrom
vb/stylelint-plugin
May 4, 2022
Merged

feat: add stylelint-plugin#115
valerybugakov merged 4 commits intomainfrom
vb/stylelint-plugin

Conversation

@valerybugakov
Copy link
Copy Markdown
Member

@valerybugakov valerybugakov commented May 4, 2022

Context

Moving the stylelint-plugin from the main Sourcegraph repo to leverage logic used for codemods later.
This PR also introduces:

  1. Typescript support for custom Stylelint rules.
    interface RuleConfig {
    regexp: string
    }
    export const filenameMatchRegexRule = createPlugin<RuleConfig>(ruleName, (isEnabled, config) => {
  2. Infrastructure to test new rules.
    testRule({
    ruleName,
    config: [true, { paths: ['bootstrap*', 'reactstrap/index.css'] }],
    codeFilename: 'packages/stylelint-plugin/test.css',
    accept: [
    {
    code: '@import "reactstrap/not-banned.css"',
    description: 'Absolute import',
    },
    {
    code: '@import "./branded/src/global-styles/index.scss";',
    description: 'Relative import',
    },
    {
    code: '@import "../../branded/src/global-styles/index.scss";',
    description: 'Deep relative import',
    },
    ],
    reject: [
    {
    code: '@import "reactstrap/index.css";',
    description: 'Banned import exact path',
    message: messages.rejected('reactstrap/index.css'),
    },
    {
    code: '@import "bootstrap";',
    description: 'Banned import via glob',
    message: messages.rejected('bootstrap'),
    },
    {
    code: '@import "bootstrap/scss/functions";',
    description: 'Banned nested import via glob',
    message: messages.rejected('bootstrap/scss/functions'),
    },
    ],
    })
  3. Updates the stylelint package to the version used in the main Sourcegraph repo.
  4. The new no-restricted-imports rule that we can use to ban imports from packages that we want to migrate from. E.g., bootstrap.
    export const ruleName = '@sourcegraph/no-restricted-imports'

Integration plan

  1. After merging this PR, the stylelint-plugin will be published to NPM.
  2. Then, we can install it in the main Sourcegraph repo and drop the JS version defined there.

Test plan

  1. cd packages/stylelint-plugin && yarn link
  2. cd main-sourcegraph-repo && yarn link "@sourcegraph/stylelint-plugin-sourcegraph"

@valerybugakov valerybugakov self-assigned this May 4, 2022
Copy link
Copy Markdown
Contributor

@umpox umpox left a comment

Choose a reason for hiding this comment

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

Nice, LGTM - Going to be really helpful for future lint rules!

Open Q: Should this repo still be called codemod? Feels like codemod is more of a subset of code-enforcement or code-quality now, WDYT?

@valerybugakov valerybugakov merged commit 309ca9b into main May 4, 2022
@valerybugakov valerybugakov deleted the vb/stylelint-plugin branch May 4, 2022 10:43
@github-actions github-actions bot mentioned this pull request May 4, 2022
@valerybugakov
Copy link
Copy Markdown
Member Author

Should this repo still be called codemod? Feels like codemod is more of a subset of code-enforcement or code-quality now, WDYT?

@umpox, what about Eunomia? 😃

In Greek mythology, Eunomia (Ancient Greek: Εὐνομία) was a minor goddess of law and legislation (her name can be translated as "good order", "governance according to good laws")

Seriously speaking, I like the code-quality option. We would also need to update internal links in the package.json files.

@umpox
Copy link
Copy Markdown
Contributor

umpox commented May 4, 2022

Hah, I actually kinda like Eunomia!

If we ever implement "chaos engineering" we'd have to have a repo called Dysnomia 😁

@valerybugakov
Copy link
Copy Markdown
Member Author

All-in Greek mythology! 🚀

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.

2 participants