Skip to content

Commit

Permalink
feat(eslint-config): enable sonar/deprecation to replace tslint's
Browse files Browse the repository at this point in the history
  • Loading branch information
JounQin committed Mar 2, 2021
1 parent ecd422d commit 0679fcf
Show file tree
Hide file tree
Showing 10 changed files with 166 additions and 84 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
- [@1stg/babel-preset](./packages/babel-preset/CHANGELOG.md)
- [@1stg/browserslist-config](./packages/browserslist-config/CHANGELOG.md)
- [@1stg/commitlint-config](./packages/commitlint-config/CHANGELOG.md)
- [@1stg/common-config](./packages/common-config/CHANGELOG.md)
- [@1stg/eslint-config](./packages/eslint-config/CHANGELOG.md)
- [@1stg/husky-config](./packages/husky-config/CHANGELOG.md)
- [@1stg/lib-config](./packages/lib-config/CHANGELOG.md)
Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"check:stylelint": "stylelint-config-prettier-check",
"check:tslint": "tslint-config-prettier-check ./tslint.json",
"lint": "run-p lint:*",
"lint:css": "stylelint --cache --config stylelint.common.js 'tests/*.{css,less}'",
"lint:css": "stylelint --cache --config stylelint.common.js 'tests/*.{css,html,less}'",
"lint:es": "cross-env PARSER_NO_WATCH=true eslint . --cache --ext js,jsx,md,mdx,ts,tsx,vue -f friendly",
"lint:scss": "stylelint --cache 'tests/*.{scss,vue}'",
"lint:ts": "tslint -p . -t stylish",
Expand All @@ -30,15 +30,16 @@
"@types/node": "^14.14.31",
"@types/react": "^17.0.2",
"@types/unist": "^2.0.3",
"core-js": "^3.9.0",
"core-js": "^3.9.1",
"lerna": "^3.22.1",
"npm-run-all": "^4.1.5",
"react": "^17.0.1",
"svelte": "^3.34.0",
"rxjs": "^6.6.6",
"svelte": "^3.35.0",
"ts-jest": "^26.5.2",
"tslint": "^6.1.3",
"type-coverage": "^2.16.3",
"typescript": "^4.2.2",
"typescript": "^4.1.5",
"vue": "^2.6.12",
"yarn-deduplicate": "^3.1.0"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-preset/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@babel/helper-plugin-utils": "^7.13.0",
"@babel/plugin-proposal-class-properties": "^7.13.0",
"@babel/plugin-proposal-decorators": "^7.13.5",
"@babel/preset-env": "^7.13.8",
"@babel/preset-env": "^7.13.9",
"@babel/preset-react": "^7.12.13",
"@babel/preset-typescript": "^7.13.0",
"@pkgr/utils": "^0.6.0",
Expand All @@ -27,7 +27,7 @@
"babel-plugin-transform-remove-console": "^6.9.4",
"babel-plugin-transform-typescript-metadata": "^0.3.1",
"babel-preset-proposal-typescript": "^2.0.0",
"core-js": "^3.9.0",
"core-js": "^3.9.1",
"fast-async": "^7.0.6"
},
"publishConfig": {
Expand Down
3 changes: 3 additions & 0 deletions packages/eslint-config/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module.exports = {
'standard',
'plugin:prettier/recommended',
],
plugins: ['sonar'],
settings: {
node: {
allowModules,
Expand Down Expand Up @@ -53,6 +54,7 @@ module.exports = {
allowWholeFile: true,
},
],
'eslint-comments/no-unused-disable': 2,
'import/order': [
2,
{
Expand Down Expand Up @@ -88,6 +90,7 @@ module.exports = {
'node/no-unpublished-require': 0,
'prefer-const': 2,
'prefer-object-spread': 2,
'sonar/deprecation': 1,
'unicorn/catch-error-name': [
2,
{
Expand Down
7 changes: 4 additions & 3 deletions packages/eslint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
"@babel/eslint-parser": "^7.13.8",
"@babel/eslint-plugin": "^7.13.0",
"@pkgr/utils": "^0.6.0",
"@typescript-eslint/eslint-plugin": "^4.15.2",
"@typescript-eslint/eslint-plugin-tslint": "^4.15.2",
"@typescript-eslint/parser": "^4.15.2",
"@typescript-eslint/eslint-plugin": "^4.16.1",
"@typescript-eslint/eslint-plugin-tslint": "^4.16.1",
"@typescript-eslint/parser": "^4.16.1",
"eslint-config-prettier": "^8.1.0",
"eslint-config-standard": "^16.0.2",
"eslint-config-standard-jsx": "^10.0.0",
Expand All @@ -31,6 +31,7 @@
"eslint-plugin-promise": "^4.3.1",
"eslint-plugin-react": "^7.22.0",
"eslint-plugin-react-hooks": "^4.2.0",
"eslint-plugin-sonar": "^0.2.0",
"eslint-plugin-sonarjs": "^0.6.0",
"eslint-plugin-svelte": "^1.1.2",
"eslint-plugin-unicorn": "^28.0.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/prettier-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"dependencies": {
"@prettier/plugin-pug": "^1.13.5",
"@prettier/plugin-ruby": "^1.5.2",
"@prettier/plugin-ruby": "^1.5.3",
"@prettier/plugin-xml": "^0.13.0",
"prettier-plugin-pkg": "^0.8.0",
"prettier-plugin-sh": "^0.6.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/tslint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"codelyzer": "^6.0.1",
"ng-tslint": "^1.1.0",
"tslint-angular": "^3.0.3",
"tslint-config-eslint": "^0.2.2",
"tslint-config-eslint": "^0.3.0",
"tslint-config-prettier": "^1.18.0",
"tslint-plugin-prettier": "^3.0.0-beta.0",
"tslint-react": "^5.0.0",
Expand Down
42 changes: 42 additions & 0 deletions tests/_test.ts
Original file line number Diff line number Diff line change
@@ -1 +1,43 @@
/**
* @deprecated This has been deprecated, no not use it
*/
export const content = 'Hello World'

export interface PartialObserver<T> {
value: T
}

export interface Subscription {
unsubscribe(): void
}

export declare class TestCase<T = unknown> {
subscribe(observer?: PartialObserver<T>): Subscription
/** @deprecated Use an observer instead of a complete callback */
subscribe(
next: null | undefined,
error: null | undefined,
complete: () => void,
): Subscription

/** @deprecated Use an observer instead of an error callback */
subscribe(
next: null | undefined,
error: (error: unknown) => void,
complete?: () => void,
): Subscription

/** @deprecated Use an observer instead of a complete callback */
subscribe(
// eslint-disable-next-line @typescript-eslint/unified-signatures
next: (value: T) => void,
error: null | undefined,
complete: () => void,
): Subscription

subscribe(
next?: (value: T) => void,
error?: (error: unknown) => void,
complete?: () => void,
): Subscription
}
16 changes: 15 additions & 1 deletion tests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ import fs from 'fs'
import path from 'path'
import { promisify } from 'util'

import { interval } from 'rxjs'
import { Position } from 'unist'

import { content } from './_test'
import { TestCase, content } from './_test'

promisify(fs.readFile)

/**
* @deprecated
*/
class Basic {
prop: string = content
}
Expand Down Expand Up @@ -45,6 +49,7 @@ foo(() => {

const obj: Record<string, string | undefined> = {}

// eslint-disable-next-line sonar/deprecation -- this is expected
export default class Test extends Basic implements X {
path: typeof path

Expand All @@ -67,3 +72,12 @@ try {
const y = obj.x
console.log(y)
} catch {}

/**
* unexpected on ts 4.2, related to:
* @link https://github.com/ReactiveX/rxjs/issues/6060
* @link https://community.sonarsource.com/t/unexpected-deprecation-warnings-reported/39441
*/
interval(1000).subscribe()

new TestCase<number>().subscribe()
Loading

0 comments on commit 0679fcf

Please sign in to comment.