Skip to content

eslint rules for firebase projects #1831

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

Merged
merged 3 commits into from
Jun 4, 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
159 changes: 159 additions & 0 deletions config/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
{
"env": {
"browser": true,
"es6": true,
"node": true
},
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint",
"@typescript-eslint/tslint"
],
"parserOptions": {
"ecmaVersion": 2015,
"sourceType": "module"
},
"overrides": [
{
"files": [
"*test.ts",
"**/test/**/*.ts"
],
"rules": {
"no-unused-expressions": "off"
}
}
],
"rules": {
"curly": [
"error",
"all"
],
"guard-for-in": "error",
"no-extra-label": "error",
"no-unused-labels": "error",
"new-parens": "error",
"no-new-wrappers": "error",
"no-debugger": "error",
"no-duplicate-case": "error",
"no-throw-literal": "error",
"no-return-await": "error",
"no-unsafe-finally": "error",
"no-unused-expressions": [
"error",
{
"allowShortCircuit": true
}
],
"no-var": "error",
"object-shorthand": "error",
"prefer-arrow-callback": [
"error",
{
"allowNamedFunctions": true
}
],
"prefer-const": [
"error",
{
"destructuring": "all"
}
],
"radix": "error",
"default-case": "error",
"eqeqeq": [
"error",
"always",
{
"null": "ignore"
}
],
"no-caller": "error",
"no-cond-assign": ["error", "always"],
"use-isnan": "error",
"camelcase": "error",
"id-blacklist": [
"error",
"any",
"number",
"string",
"boolean"
],
"@typescript-eslint/array-type": [
"error",
"array-simple"
],
"@typescript-eslint/ban-types": [
"error",
{
"types": {
"Object": "Use object instead.",
"String": "Use 'string' instead.",
"Number": "Use 'number' instead.",
"Boolean": "Use 'boolean' instead."
}
}
],
"@typescript-eslint/class-name-casing": "error",
"@typescript-eslint/interface-name-prefix": [
"error",
"never"
],
"@typescript-eslint/prefer-interface": "error",
"@typescript-eslint/explicit-member-accessibility": [
"error",
{
"accessibility": "no-public",
"overrides": {
"parameterProperties": "explicit"
}
}
],
"@typescript-eslint/no-angle-bracket-type-assertion": "error",
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-namespace": [
"error",
{
"allowDeclarations": true
}
],
"@typescript-eslint/no-triple-slash-reference": "error",
"@typescript-eslint/no-require-imports": "error",
"@typescript-eslint/no-useless-constructor": "error",
"@typescript-eslint/semi": "error",
"@typescript-eslint/explicit-function-return-type": [
"error",
{
"allowExpressions": true
}
],
"@typescript-eslint/no-unused-vars": [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW- Looking through the Firestore errors, this is the other rule we run into a lot. Our current tslint rules prevent unused variables but allow unused arguments, and we have a lot of violations (~170 though some of those are for _, see below), and the ones I've looked at are mostly intentional... Basically there are many places where a function is implementing some contract and we want the function signature to convey the contract, even if the function implementation doesn't need everything provided by the contract.

As a simple example:

      return documentsStore
        .iterate((key, doc) => {
          const path = new ResourcePath(key);
          ...
        });

Here, It so happens that doc isn't needed, but the iterate function will be passed 'key' and 'doc', and it would be confusing to make it look like it's not!

We also have various interfaces with multiple implementations, and not all implementations need all the function arguments provided... but it's still worth explicitly conforming to the contract.

We could suppress all of these, but I wouldn't be excited about adding that kind of clutter... So I would suggest that we make the ignore pattern be something like "^_" and then change all of the intentionally unused parameters to just be prefixed with an underscore, e.g. "_doc" above. That way we can keep the rule, but cleanly mark all the intentional ones without it being too awkward.

WDYT?

Copy link
Member Author

@Feiyang1 Feiyang1 Jun 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! That's the intention, but I made a mistake in the regex (I meant to have ^_.*$). Update the regex to "^_".

"error",
{
"varsIgnorePattern": "^_",
"argsIgnorePattern": "^_"
}
],
"@typescript-eslint/tslint/config": [
"error",
{
"rules": {
"ban": [true,
{"name": ["it", "skip"]},
{"name": ["it", "only"]},
{"name": ["describe", "skip"]},
{"name": ["describe", "only"]},
{"name": ["xit"]},
{"name": ["xdescribe"]},
{"name": "parseInt", "message": "tsstyle#type-coercion"},
{"name": "parseFloat", "message": "tsstyle#type-coercion"},
{"name": "Array", "message": "tsstyle#array-constructor"}
],
"jsdoc-format": true,
"no-floating-promises": true,
"arrow-return-shorthand": true
}
}
]
}
}
6 changes: 6 additions & 0 deletions packages/app/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "../../config/.eslintrc.json",
"parserOptions": {
"project": "tsconfig.json"
}
}
8 changes: 7 additions & 1 deletion packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"dist"
],
"scripts": {
"lint": "eslint -c .eslintrc.json '**/*.ts' --ignore-path '../../.gitignore'",
"lint:fix": "eslint --fix -c .eslintrc.json '**/*.ts'",
"build": "rollup -c",
"dev": "rollup -c -w",
"test": "run-p test:browser test:node",
Expand Down Expand Up @@ -58,7 +60,11 @@
"ts-loader": "5.4.5",
"ts-node": "8.1.0",
"typescript": "3.4.5",
"webpack": "4.30.0"
"webpack": "4.30.0",
"eslint": "5.16.0",
"@typescript-eslint/parser": "1.9.0",
"@typescript-eslint/eslint-plugin": "1.9.0",
"@typescript-eslint/eslint-plugin-tslint": "1.9.0"
},
"repository": {
"directory": "packages/app",
Expand Down
6 changes: 6 additions & 0 deletions packages/firestore/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "../../config/.eslintrc.json",
"parserOptions": {
"project": "tsconfig.json"
}
}
7 changes: 6 additions & 1 deletion packages/firestore/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"dev": "rollup -c -w",
"lint": "tslint -p tsconfig.json -c tslint.json 'src/**/*.ts' 'test/**/*.ts'",
"lint:fix": "tslint --fix -p tsconfig.json -c tslint.json 'src/**/*.ts' 'test/**/*.ts'",
"lint:eslint": "eslint -c .eslintrc.json '**/*.ts' --ignore-path '../../.gitignore'",
"prettier": "prettier --write 'src/**/*.js' 'test/**/*.js' 'src/**/*.ts' 'test/**/*.ts'",
"test": "run-s lint test:all",
"test:all": "run-p test:browser test:node",
Expand Down Expand Up @@ -76,7 +77,11 @@
"tslint": "5.16.0",
"typescript": "3.4.5",
"webpack": "4.30.0",
"yargs": "13.2.2"
"yargs": "13.2.2",
"eslint": "5.16.0",
"@typescript-eslint/parser": "1.9.0",
"@typescript-eslint/eslint-plugin": "1.9.0",
"@typescript-eslint/eslint-plugin-tslint": "1.9.0"
},
"repository": {
"directory": "packages/firestore",
Expand Down
Loading