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

Add @stylelint/npm-package-json-lint-config #6

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

Conversation

ntwb
Copy link
Member

@ntwb ntwb commented Apr 12, 2020

This PR adds the https://npmpackagejsonlint.org/ package

It enforces a set of package.json properties that should be included in each stylelint org repo package.json

https://github.com/stylelint/npm-package-json-lint-config/blob/master/lib/npm-package-json-lint-config.js#L7-L31

e.g.:

  'valid-values-author': ['error', ['stylelint']],
  'valid-values-license': ['error', ['MIT']],

In the near future it will also include the funding property, it works in tandem with the Prettier formatting but ensures that proreties contain both the correct org values and that they haven't been omitted from a repo either.


It also adds Jest and a basic test.

@ntwb ntwb requested a review from jeddy3 April 12, 2020 12:34
Copy link
Member

@jeddy3 jeddy3 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 this! Enforcing conventions with tooling is always a win.

I've requested some changes. Some of which will need to be addressed upstream in the shared config.

.github/workflows/nodejs.yml Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
package.json Show resolved Hide resolved
@ntwb
Copy link
Member Author

ntwb commented Apr 13, 2020

There's an extra 2859084 change in this PR, I moved prettier from devDependencies to dependencies, the benefit of this is that this shared config ships with Prettier now and there is no longer a need to also add Prettier to the repos that use it:

https://github.com/stylelint/stylelint/blob/master/package.json#L180

This is no longer required, and is in line with this same new package:
https://github.com/stylelint/npm-package-json-lint-config/blob/master/package.json#L60-L63

Copy link
Member

@jeddy3 jeddy3 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 making the changes.

I've made one minor suggestion and a query below.

There's an extra 2859084 change in this PR, I moved prettier from devDependencies to dependencies,

Will we need to publish a new version of this package whenever Prettier publishes? If there aren't any downsides, should we be recommending that stylelint shared config authors do the same, and should we do the same for our ESLint shared config? I guess it could get messy if you extend two configs which have different versions of stylelint/ESLint/PackageJsonLint as dependencies.

I think I prefer not including the tools within the configs.

.github/workflows/nodejs.yml Outdated Show resolved Hide resolved
@hudochenkov
Copy link
Member

I think I prefer not including the tools within the configs.

Agree.

@ntwb
Copy link
Member Author

ntwb commented Apr 13, 2020

We will have around ~10 repos using Prettier, the @stylelint/prettier-config package is intended for use by the stylelint organization, primarily it is an internal tool used to benefit stylelint and not has a broad shared configuration for non-stylelint projects to be used

When a new release of Prettier is released, depending on if it is a major, minor, or patch release we can update this PR once, versus the alternative of having to update each of the ~10 repos with the Prettier update.

Likewise, ESLint, the same for ESLint, update ~10 repos or 1 repo

Further, as has been taking place, aligning the naming of the scripts being used across the repos for consistent script renaming, e.g npm run format

My plan is that once most of the repos using these packages are up to date is to remove them all from the these repos completely, these packages would then ship as part of the @stylelint/scripts package, this would remove ~90% of all stylelint org repos devDependencies with one single package.

The ideology behind this comes from the kcd-scripts package to which we developed the WordPress scripts to follow suit:

https://github.com/kentcdodds/kcd-scripts/blob/master/package.json#L33-L88
https://github.com/WordPress/gutenberg/blob/master/packages/scripts/package.json#L35-L75

Each of ESLint, Prettier, Husky, Lint Staged are all included in this same manner, the maintenance level of dependabot PRs each month will drop by a significant magnitude IMHO

The end result is a set of common scripts for use in each repo with the configuration and parent tool (ESLint, Prettier etc) included in the distribution:

{
    "scripts": {
        "build": "stylelint-scripts build",
        "check-engines": "stylelint-scripts check-engines",
        "check-licenses": "stylelint-scripts check-licenses",
        "format:js": "stylelint-scripts format-js",
        "lint:css": "stylelint-scripts lint-style",
        "lint:js": "stylelint-scripts lint-js",
        "lint:md:docs": "stylelint-scripts lint-md-docs",
        "lint:md:js": "stylelint-scripts lint-md-js",
        "lint:pkg-json": "stylelint-scripts lint-pkg-json",
        "packages-update": "stylelint-scripts packages-update",
        "start": "stylelint-scripts start",
        "test:e2e": "stylelint-scripts test-e2e",
        "test:unit": "stylelint-scripts test-unit-js"
    }
}

@hudochenkov
Copy link
Member

When a new release of Prettier is released, depending on if it is a major, minor, or patch release we can update this PR once, versus the alternative of having to update each of the ~10 repos with the Prettier update.

Likewise, ESLint, the same for ESLint, update ~10 repos or 1 repo

We'll have to update all repositories anyway. If we bump Prettier version in this repository, then we'll have to release new config versions. And update all ~10 repositories with new config.

My plan is that once most of the repos using these packages are up to date is to remove them all from the these repos completely, these packages would then ship as part of the @stylelint/scripts package, this would remove ~90% of all stylelint org repos devDependencies with one single package.

This idea is good. More about it https://kentcdodds.com/blog/concerning-toolkits

@jeddy3
Copy link
Member

jeddy3 commented Apr 13, 2020

these packages would then ship as part of the @stylelint/scripts package

That's an excellent idea!

As both Prettier and this config will be bundled together in a shared scripts package, I don't think we need to couple them here. I think I'd prefer to have configs behave consistently regardless of their intended use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants