-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* create profiles, compose packages, add github config * update readme * add info about stylelint and prettier * update configs * improvements, fixes * cr fixes
- Loading branch information
Showing
16 changed files
with
6,076 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* @nordcloud/augeas |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# What | ||
|
||
- What was done in this Pull Request | ||
- How was it before | ||
- Any other information that may be useful for the dev to review Pull Request | ||
|
||
## Compatibility | ||
|
||
- [ ] Does this change maintain backward compatibility? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
name: Publish to NPM | ||
on: | ||
release: | ||
types: [created] | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-node@v2 | ||
with: | ||
node-version: "16" | ||
- run: echo "registry=https://registry.npmjs.org/" > .npmrc | ||
- run: echo "//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}" >> .npmrc | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_KEY }} | ||
- run: npm publish --access public |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
engine-strict=true | ||
legacy-peer-deps=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,146 @@ | ||
# eslint-config-pat | ||
Shareable ESLint config for PAT projects | ||
# @nordcloud/eslint-config-pat | ||
|
||
A TypeScript ESLint ruleset designed for Nordcloud's Platform & Tools | ||
|
||
## Implementation | ||
|
||
- **Monorepo friendly:** The `@nordcloud/eslint-config-pat` package has direct dependencies on all the ESLint plugins | ||
that it needs. This avoids encumbering each consuming project with the obligation to satisfy a peer dependencies. | ||
It also ensures that the installed plugin versions were tested for compatibility together. | ||
|
||
- **Designed for Prettier:** The `@nordcloud/eslint-config-pat` ruleset is designed to be used together with | ||
the [Prettier](https://prettier.io/) code formatter. | ||
Prettier avoids frivolous debates: its defaults have already been debated | ||
at length and adopted by a sizeable community. | ||
|
||
- **Minimal configuration:** To use this ruleset, your **.eslintrc.js** will need to choose one **"profile"** | ||
and possibly one or two **"mixins"** that cover special cases | ||
|
||
## Getting started in 3 steps | ||
|
||
Applying the ruleset to your project is quick and easy. You install the package, then create an **.eslintrc.js** file | ||
and select an appropriate project profile. Optionally you can also add some "mixins" to enable additional rules. | ||
Let's walk through those steps in more detail. | ||
|
||
### 1. Install the package | ||
|
||
To install the package, do this: | ||
|
||
```sh | ||
cd your-project-folder | ||
npm install -D eslint typescript prettier @nordcloud/eslint-config-pat | ||
``` | ||
|
||
### 2. Choose one profile | ||
|
||
The ruleset currently supports two different "profile" strings, which select lint rules applicable for | ||
your project: | ||
|
||
- `@nordcloud/eslint-config-pat/profile/node` - This profile enables lint rules intended for a general Node.js project, | ||
typically a web service. | ||
|
||
- `@nordcloud/eslint-config-pat/profile/web-app` - This profile enables lint rules intended for a web application, for | ||
example security rules that are relevant to web browser APIs such as DOM. | ||
_Also use this profile if you are creating a library that can be consumed by both Node.js and web applications._ | ||
|
||
After choosing a profile, create an **.eslintrc.js** config file that provides the Node.js `__dirname` context | ||
for TypeScript. Add your profile string in the `extends` field, as shown below: | ||
|
||
**.eslintrc.js** | ||
|
||
```ts | ||
// This is a workaround for https://github.com/eslint/eslint/issues/3458 | ||
require("@nordcloud/eslint-config-pat/patch/modern-module-resolution"); | ||
|
||
module.exports = { | ||
extends: ["@nordcloud/eslint-config-pat/profile/node"], // <---- put your profile string here | ||
parserOptions: { tsconfigRootDir: __dirname }, | ||
}; | ||
``` | ||
|
||
### 3. Add any relevant mixins | ||
|
||
Optionally, you can add some "mixins" to your `extends` array to opt-in to some extra behaviors. | ||
|
||
Important: Your **.eslintrc.js** `"extends"` field must load mixins after the profile entry. | ||
|
||
#### `@nordcloud/eslint-config-pat/mixins/react` | ||
|
||
For projects using the [React](https://reactjs.org/) library, the `@nordcloud/eslint-config-pat/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("@nordcloud/eslint-config-pat/patch/modern-module-resolution"); | ||
|
||
module.exports = { | ||
extends: [ | ||
"@nordcloud/eslint-config-pat/profile/web-app", | ||
"@nordcloud/eslint-config-pat/mixins/react", // <---- | ||
], | ||
parserOptions: { tsconfigRootDir: __dirname }, | ||
|
||
settings: { | ||
react: { | ||
version: "16.13.0", // <---- | ||
}, | ||
}, | ||
}; | ||
``` | ||
|
||
### 4. Prettier | ||
|
||
The `@nordcloud/eslint-config-pat` ruleset is intended to be used with the Prettier code formatter. For general | ||
instructions on setting that up, please refer to the [Prettier docs](https://prettier.io/docs/en/index.html). | ||
|
||
```sh | ||
cd your-project-folder | ||
npm install -D prettier | ||
``` | ||
|
||
Add the prettier config file in the root directory: | ||
|
||
**prettier.config.js** | ||
|
||
```ts | ||
module.exports = { | ||
...require("@nordcloud/eslint-config-pat/prettier.config.js"), | ||
// Your overrides | ||
}; | ||
``` | ||
|
||
### 5. Stylelint | ||
|
||
It's possible to use common [Stylelint](https://stylelint.io/) config from this package, you must setup stylelint first: | ||
|
||
```sh | ||
cd your-project-folder | ||
npm install -D stylelint stylelint-config-recommended stylelint-config-styled-components stylelint-processor-styled-components | ||
``` | ||
|
||
Add the stylelint config file in the root directory: | ||
|
||
**stylelint.config.js** | ||
|
||
```ts | ||
module.exports = { | ||
extends: "@nordcloud/eslint-config-pat/stylelint.config.js", | ||
rules: { | ||
// Your overrides | ||
}, | ||
}; | ||
``` | ||
|
||
## Credits | ||
|
||
- Based on [@rushstack/eslint-config](https://github.dev/microsoft/rushstack/tree/master/stack/eslint-config) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. | ||
// See LICENSE in the project root for license information. | ||
|
||
throw new Error( | ||
"The index.js entry point has been removed. Please update your ESLint configuration to import one of the" + | ||
' profile paths such as "@nordcloud/eslint-config-pat/profile/web-app" or "@nordcloud/eslint-config-pat/profile/node.' + | ||
"\n\nSee the documentation for details: https://www.npmjs.com/package/@nordcloud/eslint-config-pat" | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
// This mixin applies some additional checks for projects using the React library. For more information, | ||
// please see the README.md for "@nordcloud/eslint-config-pat". | ||
module.exports = { | ||
parserOptions: { | ||
ecmaFeatures: { | ||
jsx: true, | ||
}, | ||
}, | ||
|
||
settings: { | ||
// Link component used by React Router and Next.js | ||
linkComponents: ["Hyperlink", { name: "Link", linkAttribute: "to" }], | ||
react: { | ||
// The default value is "detect". Automatic detection works by loading the entire React library | ||
// into the linter's process, which is inefficient. It is recommended to specify the version | ||
// explicity. For details, see README.md for "@nordcloud/eslint-config-pat". | ||
version: "detect", | ||
}, | ||
}, | ||
|
||
overrides: [ | ||
{ | ||
// Declare an override that applies to TypeScript files only | ||
files: ["*.ts", "*.tsx"], | ||
|
||
extends: [ | ||
"plugin:react/recommended", | ||
"plugin:react-hooks/recommended", | ||
"plugin:jsx-a11y/recommended", | ||
], | ||
|
||
rules: { | ||
"fp/no-mutation": [ | ||
"warn", | ||
{ | ||
commonjs: true, | ||
exceptions: [ | ||
{ object: "window", property: "location" }, | ||
// Usage with React refs | ||
{ property: "current" }, | ||
], | ||
}, | ||
], | ||
|
||
// avoid false-positives for module bundlers resolution | ||
"import/no-unresolved": "off", | ||
|
||
"import/no-internal-modules": [ | ||
"off", | ||
{ | ||
allow: ["@testing-library/**"], | ||
}, | ||
], | ||
"import/order": [ | ||
"error", | ||
{ | ||
alphabetize: { | ||
order: "asc", | ||
caseInsensitive: true, | ||
}, | ||
groups: [ | ||
"builtin", | ||
"external", | ||
"internal", | ||
"parent", | ||
"sibling", | ||
"index", | ||
], | ||
pathGroups: [ | ||
// GraphQL Codegen output | ||
{ | ||
pattern: "~/generated/**", | ||
group: "internal", | ||
position: "before", | ||
}, | ||
// Common aliased import pattern used in Nordcloud | ||
{ | ||
pattern: "~/**", | ||
group: "internal", | ||
}, | ||
// Nordcloud's React component library | ||
{ | ||
pattern: "@nordcloud/gnui", | ||
group: "external", | ||
position: "after", | ||
}, | ||
{ | ||
pattern: "react", | ||
group: "external", | ||
position: "before", | ||
}, | ||
], | ||
pathGroupsExcludedImportTypes: [ | ||
"react", | ||
"~/generated/**", | ||
"@nordcloud/gnui", | ||
], | ||
}, | ||
], | ||
|
||
// eslint-plugin-react-hooks | ||
"react-hooks/exhaustive-deps": "warn", | ||
"react-hooks/rules-of-hooks": "error", | ||
|
||
// eslint-plugin-react | ||
"react/jsx-no-useless-fragment": "off", | ||
"react/prop-types": "off", | ||
"react/display-name": "off", | ||
"react/function-component-definition": [ | ||
"warn", | ||
{ | ||
namedComponents: "function-declaration", | ||
unnamedComponents: "arrow-function", | ||
}, | ||
], | ||
"react/jsx-pascal-case": ["error", { allowNamespace: true }], | ||
"react/jsx-boolean-value": ["error", "never"], | ||
"react/jsx-key": "error", | ||
"react/self-closing-comp": [ | ||
"error", | ||
{ | ||
component: true, | ||
html: true, | ||
}, | ||
], | ||
}, | ||
}, | ||
{ | ||
files: [ | ||
// Test files | ||
"*.test.ts", | ||
"*.test.tsx", | ||
"*.spec.ts", | ||
"*.spec.tsx", | ||
|
||
// Facebook convention | ||
"**/__mocks__/*.ts", | ||
"**/__mocks__/*.tsx", | ||
"**/__tests__/*.ts", | ||
"**/__tests__/*.tsx", | ||
], | ||
extends: ["plugin:jest-dom/recommended", "plugin:testing-library/react"], | ||
rules: { | ||
// eslint-plugin-jest-dom | ||
"jest-dom/prefer-in-document": "off", | ||
|
||
// eslint-plugin-testing-library | ||
"testing-library/prefer-screen-queries": "warn", | ||
|
||
// eslint-plugin-fp | ||
// for...of loops are useful for awaiting multiple testing library queries | ||
"fp/no-loops": "off", | ||
}, | ||
}, | ||
], | ||
}; |
Oops, something went wrong.