Add ESLint (#3)

This commit is contained in:
Justin Fagnani
2019-12-18 11:35:37 -08:00
committed by GitHub
parent d50f5a7c7e
commit 7b6b9cf0b4
5 changed files with 742 additions and 4 deletions

25
.eslintrc.json Normal file
View File

@@ -0,0 +1,25 @@
{
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
"no-unexpected-multiline": "off",
"@typescript-eslint/indent": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/no-unused-vars": ["warn", {
"argsIgnorePattern": "^_"
}]
}
}

View File

@@ -12,7 +12,7 @@ npm i
## Build ## Build
This sample uses the TypeScript compiler to produce JavaScript that runs in modern browsers, and [lit-analyzer](https://www.npmjs.com/package/lit-analyzer), a program that type-checks and lints lit-html templates. This sample uses the TypeScript compiler to produce JavaScript that runs in modern browsers.
To build the JavaScript version of your component: To build the JavaScript version of your component:
@@ -40,7 +40,7 @@ npm test
## Dev Server ## Dev Server
This sample uses [ES dev server](https://github.com/open-wc/open-wc/tree/master/packages/es-dev-server) for previewing the project without additional build steps. ES dev server handles resolving Node-style "bare" import specifiers, which aren't supported in browsers. It also automatically transpiles JavaScript and adds polyfills to support older browsers. This sample uses open-wc's [es-dev-server](https://github.com/open-wc/open-wc/tree/master/packages/es-dev-server) for previewing the project without additional build steps. ES dev server handles resolving Node-style "bare" import specifiers, which aren't supported in browsers. It also automatically transpiles JavaScript and adds polyfills to support older browsers.
To run the dev server and open the project in a new browser tab: To run the dev server and open the project in a new browser tab:
@@ -48,6 +48,18 @@ To run the dev server and open the project in a new browser tab:
npm run serve npm run serve
``` ```
## Linting
Linting of TypeScript files is provided by [ESLint](eslint.org) and [TypeScript ESLint](https://github.com/typescript-eslint/typescript-eslint). In addition, [lit-analyzer](https://www.npmjs.com/package/lit-analyzer) is used to type-check and lint lit-html templates.
The rules are mostly the recommended rules from each project, but some have been turned off to make LitElement usage easier. The recommended rules are pretty strict, so you may want to relax them by editing `.eslintrc.json` and `tsconfig.json`.
To lint the project run:
```bash
npm run lint
```
## More information ## More information
See [Get started](https://lit-element.polymer-project.org/guide/start) on the LitElement site for more information. See [Get started](https://lit-element.polymer-project.org/guide/start) on the LitElement site for more information.

697
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -6,8 +6,9 @@
"module": "my-element.js", "module": "my-element.js",
"type": "module", "type": "module",
"scripts": { "scripts": {
"build": "lit-analyzer && tsc", "build": "tsc",
"build:watch": "tsc --watch", "build:watch": "tsc --watch",
"lint": "lit-analyzer && eslint 'src/**/*.ts'",
"serve": "es-dev-server --app-index demo/index.html --node-resolve --watch --open", "serve": "es-dev-server --app-index demo/index.html --node-resolve --watch --open",
"test": "karma start karma.conf.cjs", "test": "karma start karma.conf.cjs",
"test:watch": "karma start karma.conf.cjs --auto-watch=true --single-run=false", "test:watch": "karma start karma.conf.cjs --auto-watch=true --single-run=false",
@@ -29,9 +30,12 @@
"@open-wc/testing-karma": "^3.2.19", "@open-wc/testing-karma": "^3.2.19",
"@types/chai": "^4.2.7", "@types/chai": "^4.2.7",
"@types/mocha": "^5.2.7", "@types/mocha": "^5.2.7",
"@typescript-eslint/eslint-plugin": "^2.12.0",
"@typescript-eslint/parser": "^2.12.0",
"chai": "^4.2.0", "chai": "^4.2.0",
"deepmerge": "^4.2.2", "deepmerge": "^4.2.2",
"es-dev-server": "^1.23.1", "es-dev-server": "^1.23.1",
"eslint": "^6.7.2",
"karma": "^4.4.1", "karma": "^4.4.1",
"karma-chai": "^0.1.0", "karma-chai": "^0.1.0",
"karma-mocha": "^1.3.0", "karma-mocha": "^1.3.0",