-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: convert custom tslint rules to eslint (#3917)
- Loading branch information
Showing
32 changed files
with
2,290 additions
and
70 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
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
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
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
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
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
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
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
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
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
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,114 @@ | ||
<img height="204" src="https://cloud.githubusercontent.com/assets/464822/20228152/d3f36dc2-a804-11e6-80ff-51ada2d13ea7.png"> | ||
|
||
# [Blueprint](http://blueprintjs.com/) [ESLint](https://eslint.org/) plugin | ||
|
||
Blueprint is a React UI toolkit for the web. | ||
|
||
This package contains the [ESLint](https://eslint.org/) plugin for Blueprint. It provides custom rules which are useful when developing against Blueprint libraries. | ||
|
||
**Key features:** | ||
|
||
- [Blueprint-specific rules](#Rules) for use with `@blueprintjs` components. | ||
|
||
## Installation | ||
|
||
``` | ||
yarn add @blueprintjs/eslint-plugin-blueprint | ||
``` | ||
|
||
## Usage | ||
|
||
Simply add this plugin in your `.eslintrc` file to use the add the plugin. The plugin includes Blueprint-specific rules which enforce semantics particular to usage with `@blueprintjs` packages, but does not turn them on by default. | ||
|
||
`.eslintrc` | ||
```json | ||
plugins: [ | ||
"@blueprintjs/blueprint" | ||
] | ||
``` | ||
|
||
### Rules-only usage | ||
|
||
To enable the Blueprint-specific rules, extend the `plugin:@blueprintjs/blueprint/recommended` config inside the package: | ||
|
||
`tslint.json` | ||
```diff | ||
extends: [ | ||
+ "plugin:@blueprintjs/blueprint/recommended" | ||
] | ||
``` | ||
|
||
## Rules | ||
|
||
### `@blueprintjs/blueprint/classes-constants` | ||
|
||
Enforce usage of `Classes` constants over namespaced string literals. | ||
|
||
Each `@blueprintjs` package exports a `Classes` object that contains constants for every CSS class defined by the package. While the values of the constants may change between releases, the names of the constants will remain more stable. | ||
|
||
```json | ||
{ | ||
"rules": { | ||
"@blueprintjs/blueprint/classes-constants": ["error"], | ||
} | ||
} | ||
``` | ||
|
||
```diff | ||
-const element = <div className="pt-navbar" />; | ||
+const element = <div className={Classes.NAVBAR} />; | ||
``` | ||
|
||
### `@blueprintjs/blueprint/html-components` | ||
|
||
Enforce usage of Blueprint components over regular html components. | ||
|
||
- h1-6 -> H1-6 | ||
- code -> Code | ||
- pre -> Pre | ||
- blockquote -> Blockquote | ||
- table -> HTMLTable | ||
|
||
```js | ||
{ | ||
"rules": { | ||
"@blueprintjs/blueprint/html-components": ["error"], | ||
} | ||
} | ||
``` | ||
|
||
### `@blueprintjs/blueprint/icon-components` | ||
|
||
Enforce usage of JSX `Icon` components over `IconName` string literals (or vice-versa) in `icon` JSX props. Note that this rule only supports hardcoded values in the `icon` prop; it does not handle expressions or conditionals. | ||
|
||
A fixer is available for this rule that will convert between string literals and named `Icon` components. Note that the implementation is naive and may require intervention, such as to import a component or fix an invalid name. | ||
|
||
Named icon components (`TickIcon`, `GraphIcon`, etc) can be imported from the `@blueprintjs/icons` package. | ||
|
||
This rule is disabled in the `blueprint-rules` config as it is most useful to ensure that the `@blueprintjs/icons` package can be tree-shaken (an opt-in process which requires using components and _never_ `IconName` literals). | ||
|
||
```js | ||
{ | ||
"rules": { | ||
// default uses "component" | ||
"@blueprintjs/blueprint/icon-components": ["error"], | ||
// expanded syntax | ||
"@blueprintjs/blueprint/icon-components": ["error", "component" | "literal"] // choose one | ||
} | ||
} | ||
``` | ||
|
||
`"component"` | ||
```diff | ||
-<Button icon="tick" /> | ||
+<Button icon={<TickIcon />} /> | ||
``` | ||
|
||
`"literal"` | ||
```diff | ||
-<Button icon={<GraphIcon />} /> | ||
+<Button icon="graph" /> | ||
``` | ||
|
||
|
||
### [Full Documentation](http://blueprintjs.com/docs) | [Source Code](https://github.com/palantir/blueprint) |
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,11 @@ | ||
module.exports = { | ||
testEnvironment: 'node', | ||
transform: { | ||
'^.+\\.tsx?$': 'ts-jest', | ||
}, | ||
testRegex: '__tests__\/.+\\.test\\.ts$', | ||
collectCoverage: false, | ||
collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}'], | ||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], | ||
coverageReporters: ['text-summary', 'lcov'], | ||
}; |
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,28 @@ | ||
{ | ||
"name": "@blueprintjs/eslint-plugin-blueprint", | ||
"version": "0.0.0", | ||
"description": "ESLint rules for use with @blueprintjs packages", | ||
"main": "lib/index.js", | ||
"scripts": { | ||
"compile": "tsc -p src/", | ||
"test": "jest" | ||
}, | ||
"dependencies": { | ||
"@typescript-eslint/eslint-plugin": "^2.11.0", | ||
"@typescript-eslint/eslint-plugin-tslint": "^2.10.0", | ||
"@typescript-eslint/parser": "^2.10.0", | ||
"eslint": "^6.7.2", | ||
"jest": "^24.9.0", | ||
"ts-jest": "^24.2.0" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git@github.com:palantir/blueprint.git", | ||
"directory": "packages/eslint-plugin-blueprint" | ||
}, | ||
"author": "Palantir Technologies", | ||
"license": "Apache-2.0", | ||
"devDependencies": { | ||
"@types/dedent": "^0.7.0" | ||
} | ||
} |
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,32 @@ | ||
/* | ||
* Copyright 2017 Palantir Technologies, Inc. All rights reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import rules from "./rules"; | ||
|
||
/** | ||
* Enable Blueprint-specific lint rules defined in this package. | ||
*/ | ||
module.exports = { | ||
configs: { | ||
recommended: { | ||
plugins: ["@blueprintjs/blueprint"], | ||
rules: { | ||
"@blueprintjs/blueprint/classes-constants": "error", | ||
"@blueprintjs/blueprint/html-components": "error", | ||
}, | ||
}, | ||
}, | ||
rules, | ||
}; |
Oops, something went wrong.
1c81f3b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
chore: convert custom tslint rules to eslint (#3917)
Previews: documentation | landing | table