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 static code analysis #1970

Merged
merged 30 commits into from
May 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
182 changes: 182 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
env:
browser: true
es6: true
jest: true
extends:
- eslint:recommended
globals:
React: readonly
parserOptions:
ecmaFeatures:
jsx: true
ecmaVersion: 10
sourceType: module
root: true
rules:
# Only list rules that are not in *:recommended set
# If rules are set to disable the one in *:recommended, please elaborate the reason

# Group - Best Practices
no-async-promise-executor: error
no-await-in-loop: error
no-console:
- error
- allow:
- error
- warn
no-extra-parens: error
no-misleading-character-class: error
no-template-curly-in-string: error
require-atomic-updates: error
accessor-pairs: error
block-scoped-var: error
class-methods-use-this:
- error
- exceptMethods:
- render
complexity: error
curly: error
default-case: error
dot-notation: error
eqeqeq: error
max-classes-per-file:
- error
- 2
no-alert: error
no-caller: error
no-div-regex: error
no-else-return: error
no-empty-function: error
no-eq-null: error
no-eval: error
no-extend-native: error
no-extra-bind: error
no-extra-label: error
no-implicit-globals: error
no-implied-eval: error
no-invalid-this: error
no-iterator: error
no-labels: error
no-lone-blocks: error
no-magic-numbers:
- error
- ignore:
- 0
- 1
no-multi-spaces:
- error
- ignoreEOLComments: true
no-multi-str: error
no-new: error
no-new-func: error
no-new-wrappers: error
no-octal-escape: error
no-proto: error
no-return-assign: error
no-return-await: error
no-script-url: error
no-self-compare: error
no-sequences: error
no-throw-literal: error
no-unmodified-loop-condition: error
no-unused-expressions:
compulim marked this conversation as resolved.
Show resolved Hide resolved
- error
- allowShortCircuit: true
allowTernary: true
no-useless-call: error
no-useless-catch: error
no-useless-concat: error
no-useless-return: error
no-void: error
no-with: error
prefer-promise-reject-errors: error
radix: error
require-await: error
require-unicode-regexp: error
wrap-iife: error
yoda: error

# Group - Variables
no-label-var: error
compulim marked this conversation as resolved.
Show resolved Hide resolved

# Re-enable later
# no-shadow:
# - error
# - builtinGlobals: true
# hoist: all

no-shadow-restricted-names: error
no-undef-init: error

# "undefined" is commonly used for defaults
# no-undefined: off

no-unused-vars:
- error
- argsIgnorePattern: ^_$
varsIgnorePattern: ^_
no-use-before-define: error

# Group - Node.js and CommonJS
callback-return: error
global-require: error
handle-callback-err: error
no-buffer-constructor: error
no-mixed-requires: error
no-new-require: error
no-path-concat: error
no-sync: error

# Group - ECMAScript 6
arrow-body-style:
compulim marked this conversation as resolved.
Show resolved Hide resolved
- error
- as-needed
arrow-parens:
- error
- as-needed
arrow-spacing:
- error
- after: true
before: true
generator-star-spacing:
- error
- after

# Will produce shorter code if "off"
# no-confusing-arrow:
# - error
# - allowParens: true # This will conflict with no-extra-parens

no-duplicate-imports: error
no-useless-computed-key: error
no-useless-constructor: error
no-useless-rename: error
no-var: error
object-shorthand: error
prefer-arrow-callback: error
prefer-const: error
prefer-destructuring: error
prefer-rest-params: error
prefer-spread: error

# This will force, a + '', into, `${ a }`, which increase code length
# prefer-template: error

rest-spread-spacing:
- error
- never

# Cannot group global or local imports and sort in differently
# sort-imports:
# - error
# - ignoreCase: true

template-curly-spacing:
- error
- always
yield-star-spacing:
- error
- after
settings:
react:
version: detect
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Added something, by [@johndoe](https://github.com/johndoe), in PR [#XXX](https://github.com/Microsoft/BotFramework-WebChat/pull/XXX)
-->

### Added
- `*`: Added [`eslint`](https://npmjs.com/package/eslint/) to static code analysis, by [@compulim](https://github.com/compulim), in PR [#1970](https://github.com/microsoft/BotFramework-WebChat/pull/1970)

### Changed
- `*`: Bump to:
- [`lerna@3.13.4`](https://npmjs.com/package/lerna/),
Expand Down
18 changes: 9 additions & 9 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"build:sample": "lerna run --scope=sample-* --stream build",
"clean": "lerna run --scope=botframework-webchat* --parallel --stream clean",
"coveralls": "cat ./coverage/lcov.info | coveralls",
"eslint": "lerna run --scope=botframework-webchat* --parallel --stream eslint",
"lerna-publish": "lerna publish",
"prepublishOnly": "lerna run --scope=botframework-webchat* --scope=playground --stream prepublishOnly",
"test": "jest --no-cache",
Expand Down
98 changes: 98 additions & 0 deletions packages/bundle/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
extends:
- plugin:react/recommended
- plugin:@typescript-eslint/recommended
parser: "@typescript-eslint/parser"
plugins:
- "@typescript-eslint"
rules:
# We will rework on these rules
"@typescript-eslint/explicit-member-accessibility": off
"@typescript-eslint/explicit-function-return-type": off
"@typescript-eslint/indent": off
"@typescript-eslint/no-explicit-any": off
"@typescript-eslint/interface-name-prefix": off

react/button-has-type: error
react/default-props-match-prop-types: error
react/destructuring-assignment: error
react/forbid-component-props:
- error
- forbid:
- style
react/forbid-dom-props:
- error
- forbid:
- id
# react/forbid-prop-types: error // How to deal with Adaptive Card schema?
react/no-access-state-in-setstate: error
react/no-array-index-key: error
react/no-danger: error
react/no-did-mount-set-state: error
react/no-did-update-set-state: error
react/no-redundant-should-component-update: error
react/no-typos: error
react/no-this-in-sfc: error
react/no-unescaped-entities: error
react/no-unsafe: error
react/no-unused-prop-types: error
react/no-unused-state: error
react/no-will-update-set-state: error
react/prefer-es6-class: error
react/prefer-read-only-props: error
react/require-default-props: error
react/self-closing-comp: error
react/sort-prop-types: error
react/state-in-constructor: error
react/static-property-placement:
- error
- property assignment
react/style-prop-object: error
react/void-dom-elements-no-children: error
react/jsx-boolean-value:
- error
- always
react/jsx-closing-bracket-location:
- error
- tag-aligned
react/jsx-closing-tag-location: error
react/jsx-curly-spacing:
- error
- spacing:
objectLiterals: never
when: always
react/jsx-equals-spacing:
- error
- never
react/jsx-first-prop-new-line:
- error
- multiline-multiprop
react/jsx-handler-names: error
react/jsx-indent:
- error
- 2
react/jsx-indent-props:
- error
- 2
react/jsx-max-props-per-line:
- error
- maximum: 1
when: multiline
react/jsx-no-bind: error
react/jsx-no-literals: error
react/jsx-one-expression-per-line:
- error
- allow: literal
react/jsx-fragments:
- error
- syntax
react/jsx-pascal-case: error
react/jsx-props-no-multi-spaces: error
react/jsx-sort-default-props: error
react/jsx-sort-props: error
react/jsx-tag-spacing:
- error
- afterOpening: never
beforeClosing: never
beforeSelfClosing: always
closingSlash: never
# react/jsx-wrap-multilines: error // Conflict with no-extra-parens
Loading