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

[eslint-plugin-packlets] Initial implementation #2256

Merged
merged 23 commits into from
Oct 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "@rushstack/eslint-config",
"comment": "Add a mixin to support @rushstack/eslint-plugin-packlets",
"type": "minor"
}
],
"packageName": "@rushstack/eslint-config",
"email": "[email protected]"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "@rushstack/eslint-plugin-packlets",
"comment": "Initial release",
"type": "minor"
}
],
"packageName": "@rushstack/eslint-plugin-packlets",
"email": "[email protected]"
}
4 changes: 4 additions & 0 deletions common/config/rush/nonbrowser-approved-packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@
"name": "@rushstack/eslint-plugin",
"allowedCategories": [ "libraries" ]
},
{
"name": "@rushstack/eslint-plugin-packlets",
"allowedCategories": [ "libraries", "tests" ]
},
{
"name": "@rushstack/eslint-plugin-security",
"allowedCategories": [ "libraries" ]
Expand Down
41 changes: 41 additions & 0 deletions common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion common/config/rush/repo-state.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// DO NOT MODIFY THIS FILE. It is generated and used by Rush.
{
"pnpmShrinkwrapHash": "c4342cbb84a614c6f5b789815d32aca66d0e5b1b",
"pnpmShrinkwrapHash": "8a89f626be4d7746badda0720b4a1d771468e646",
"preferredVersionsHash": "0f2f367d951f4cd546b698d668533c1ff056e334"
}
13 changes: 13 additions & 0 deletions rush.json
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,13 @@
"shouldPublish": true,
"cyclicDependencyProjects": ["@rushstack/heft-node-rig", "@rushstack/heft"]
},
{
"packageName": "@rushstack/eslint-plugin-packlets",
"projectFolder": "stack/eslint-plugin-packlets",
"reviewCategory": "libraries",
"shouldPublish": true,
"cyclicDependencyProjects": ["@rushstack/heft-node-rig", "@rushstack/heft"]
},
{
"packageName": "@rushstack/eslint-plugin-security",
"projectFolder": "stack/eslint-plugin-security",
Expand Down Expand Up @@ -1059,6 +1066,12 @@
"reviewCategory": "tests",
"shouldPublish": false
},
{
"packageName": "packlets-tutorial",
"projectFolder": "tutorials/packlets-tutorial",
"reviewCategory": "tests",
"shouldPublish": false
},

// "webpack" folder (alphabetical order)
{
Expand Down
90 changes: 57 additions & 33 deletions stack/eslint-config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,39 +117,6 @@ Optionally, you can add some "mixins" to your `extends` array to opt-in to some
Important: Your **.eslintrc.js** `"extends"` field must load mixins after the profile entry.


#### `@rushstack/eslint-config/mixins/react`

For projects using the [React](https://reactjs.org/) library, the `"@rushstack/eslint-config/mixins/react"` mixin
enables some recommended additional rules. These rules are selected via a mixin because they require you to:

- Add `"jsx": "react"` to your **tsconfig.json**
- Configure your `settings.react.version` as shown below. This determines which React APIs will be considered
to be deprecated. (If you omit this, the React version will be detected automatically by
[loading the entire React library](https://github.com/yannickcr/eslint-plugin-react/blob/4da74518bd78f11c9c6875a159ffbae7d26be693/lib/util/version.js#L23)
into the linter's process, which is costly.)

Add the mixin to your `"extends"` field like this:

**.eslintrc.js**
```ts
// This is a workaround for https://github.com/eslint/eslint/issues/3458
require('@rushstack/eslint-config/patch/modern-module-resolution');

module.exports = {
extends: [
"@rushstack/eslint-config/profile/web-app",
"@rushstack/eslint-config/mixins/react" // <----
],
parserOptions: { tsconfigRootDir: __dirname },

settings: {
react: {
"version": "16.9" // <----
}
}
};
```

#### `@rushstack/eslint-config/mixins/friendly-locals`

Requires explicit type declarations for local variables.
Expand Down Expand Up @@ -217,6 +184,28 @@ module.exports = {
```


#### `@rushstack/eslint-config/mixins/packlets`

Packlets provide a lightweight alternative to NPM packages for organizing source files within a single project.
This system is described in the [@rushstack/eslint-plugin-packlets](https://www.npmjs.com/package/@rushstack/eslint-plugin-packlets)
documentation.

To use packlets, add the mixin to your `"extends"` field like this:

**.eslintrc.js**
```ts
// This is a workaround for https://github.com/eslint/eslint/issues/3458
require('@rushstack/eslint-config/patch/modern-module-resolution');

module.exports = {
extends: [
"@rushstack/eslint-config/profile/node",
"@rushstack/eslint-config/profile/mixins/packlets" // <----
],
parserOptions: { tsconfigRootDir: __dirname }
};
```


#### `@rushstack/eslint-config/mixins/tsdoc`

Expand All @@ -241,6 +230,41 @@ module.exports = {
};
```


#### `@rushstack/eslint-config/mixins/react`

For projects using the [React](https://reactjs.org/) library, the `"@rushstack/eslint-config/mixins/react"` mixin
enables some recommended additional rules. These rules are selected via a mixin because they require you to:

- Add `"jsx": "react"` to your **tsconfig.json**
- Configure your `settings.react.version` as shown below. This determines which React APIs will be considered
to be deprecated. (If you omit this, the React version will be detected automatically by
[loading the entire React library](https://github.com/yannickcr/eslint-plugin-react/blob/4da74518bd78f11c9c6875a159ffbae7d26be693/lib/util/version.js#L23)
into the linter's process, which is costly.)

Add the mixin to your `"extends"` field like this:

**.eslintrc.js**
```ts
// This is a workaround for https://github.com/eslint/eslint/issues/3458
require('@rushstack/eslint-config/patch/modern-module-resolution');

module.exports = {
extends: [
"@rushstack/eslint-config/profile/web-app",
"@rushstack/eslint-config/mixins/react" // <----
],
parserOptions: { tsconfigRootDir: __dirname },

settings: {
react: {
"version": "16.9" // <----
}
}
};
```


## Links

- [CHANGELOG.md](
Expand Down
21 changes: 21 additions & 0 deletions stack/eslint-config/mixins/packlets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.

// This mixin implements the "packlet" formalism for organizing source files.
// For more information, see the documentation here:
// https://www.npmjs.com/package/@rushstack/eslint-plugin-packlets
module.exports = {
plugins: ['@rushstack/eslint-plugin-packlets'],

overrides: [
{
// Declare an override that applies to TypeScript files only
files: ['*.ts', '*.tsx'],

rules: {
'@rushstack/packlets/mechanics': 'warn',
'@rushstack/packlets/circular-deps': 'warn'
}
}
]
};
1 change: 1 addition & 0 deletions stack/eslint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"dependencies": {
"@rushstack/eslint-patch": "workspace:*",
"@rushstack/eslint-plugin": "workspace:*",
"@rushstack/eslint-plugin-packlets": "workspace:*",
"@rushstack/eslint-plugin-security": "workspace:*",
"@typescript-eslint/eslint-plugin": "3.4.0",
"@typescript-eslint/experimental-utils": "3.4.0",
Expand Down
5 changes: 5 additions & 0 deletions stack/eslint-plugin-packlets/.eslintrc.js.disabled
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
NOTE: We do not invoke ESLint on this project's source files, because ESLint's module resolution (as of 6.x) is naive
and fairly brittle. It gets confused between the dependencies of this project, versus the dependencies of
@rushstack/eslint-config (which imports the previously published version of this project). Normally we solve
this problem by using Rush's "cyclicDependencyProjects" feature, but that fails because ESLint does not correctly
implement NodeJS module resolution.
24 changes: 24 additions & 0 deletions stack/eslint-plugin-packlets/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Ignore everything by default
**

# Use negative patterns to bring back the specific things we want to publish
!/bin/**
!/lib/**
!/dist/**
!ThirdPartyNotice.txt

# Ignore certain files in the above folder
/dist/*.stats.*
/lib/**/test/*

# NOTE: These don't need to be specified, because NPM includes them automatically.
#
# package.json
# README (and its variants)
# CHANGELOG (and its variants)
# LICENSE / LICENCE

## Project specific definitions
# -----------------------------

# (Add your exceptions here)
24 changes: 24 additions & 0 deletions stack/eslint-plugin-packlets/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@rushstack/eslint-plugin-packlets

Copyright (c) Microsoft Corporation. All rights reserved.

MIT License

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Loading