Skip to content

Commit

Permalink
Create eslint and prettier config files similar to ones used in fireb…
Browse files Browse the repository at this point in the history
…ase-tools repo
  • Loading branch information
alexastrum committed Jul 13, 2023
1 parent bca4fd6 commit 1a91708
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist
node_modules
134 changes: 134 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
module.exports = {
env: {
es6: true,
node: true,
},
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"plugin:jsdoc/recommended",
"google",
"prettier",
],
rules: {
"jsdoc/newline-after-description": "off",
"jsdoc/require-jsdoc": ["warn", { publicOnly: true }],
"no-restricted-globals": ["error", "name", "length"],
"prefer-arrow-callback": "error",
"prettier/prettier": "error",
"require-atomic-updates": "off", // This rule is so noisy and isn't useful: https://github.com/eslint/eslint/issues/11899
"require-jsdoc": "off", // This rule is deprecated and superseded by jsdoc/require-jsdoc.
"valid-jsdoc": "off", // This is deprecated but included in recommended configs.

"no-prototype-builtins": "warn", // TODO(bkendall): remove, allow to error.
"no-useless-escape": "warn", // TODO(bkendall): remove, allow to error.
"prefer-promise-reject-errors": "warn", // TODO(bkendall): remove, allow to error.
},
overrides: [
{
files: ["*.ts"],
rules: {
"jsdoc/require-param-type": "off",
"jsdoc/require-returns-type": "off",

// Google style guide allows us to omit trivial parameters and returns
"jsdoc/require-param": "off",
"jsdoc/require-returns": "off",

"@typescript-eslint/no-invalid-this": "error",
"@typescript-eslint/no-unused-vars": "error", // Unused vars should not exist.
"no-invalid-this": "off", // Turned off in favor of @typescript-eslint/no-invalid-this.
"no-unused-vars": "off", // Off in favor of @typescript-eslint/no-unused-vars.
eqeqeq: ["error", "always", { null: "ignore" }],
camelcase: ["error", { properties: "never" }], // snake_case allowed in properties iif to satisfy an external contract / style

"@typescript-eslint/ban-types": "warn", // TODO(bkendall): remove, allow to error.
"@typescript-eslint/explicit-function-return-type": ["warn", { allowExpressions: true }], // TODO(bkendall): SET to error.
"@typescript-eslint/no-extra-non-null-assertion": "warn", // TODO(bkendall): remove, allow to error.
"@typescript-eslint/no-floating-promises": "warn", // TODO(bkendall): remove, allow to error.
"@typescript-eslint/no-inferrable-types": "warn", // TODO(bkendall): remove, allow to error.
"@typescript-eslint/no-misused-promises": "warn", // TODO(bkendall): remove, allow to error.
"@typescript-eslint/no-unnecessary-type-assertion": "warn", // TODO(bkendall): remove, allow to error.
"@typescript-eslint/no-unsafe-argument": "warn", // TODO(bkendall): remove, allow to error.
"@typescript-eslint/no-unsafe-assignment": "warn", // TODO(bkendall): remove, allow to error.
"@typescript-eslint/no-unsafe-call": "warn", // TODO(bkendall): remove, allow to error.
"@typescript-eslint/no-unsafe-member-access": "warn", // TODO(bkendall): remove, allow to error.
"@typescript-eslint/no-unsafe-return": "warn", // TODO(bkendall): remove, allow to error.
"@typescript-eslint/no-use-before-define": ["warn", { functions: false, typedefs: false }], // TODO(bkendall): change to error.
"@typescript-eslint/no-var-requires": "warn", // TODO(bkendall): remove, allow to error.
"@typescript-eslint/prefer-includes": "warn", // TODO(bkendall): remove, allow to error.
"@typescript-eslint/prefer-regexp-exec": "warn", // TODO(bkendall): remove, allow to error.
"@typescript-eslint/prefer-string-starts-ends-with": "warn", // TODO(bkendall): remove, allow to error.
"@typescript-eslint/restrict-plus-operands": "warn", // TODO(bkendall): remove, allow to error.
"@typescript-eslint/restrict-template-expressions": "warn", // TODO(bkendall): remove, allow to error.
"no-case-declarations": "warn", // TODO(bkendall): remove, allow to error.
"no-constant-condition": "warn", // TODO(bkendall): remove, allow to error.
"no-fallthrough": "warn", // TODO(bkendall): remove, allow to error.
},
},
{
files: ["*.js"],
rules: {
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-floating-promises": "off",
"@typescript-eslint/no-misused-promises": "off",
"@typescript-eslint/no-this-alias": "off",
"@typescript-eslint/no-unsafe-argument": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-unsafe-return": "off",
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/prefer-includes": "off",
"@typescript-eslint/prefer-regexp-exec": "off",
"@typescript-eslint/restrict-plus-operands": "off",
"@typescript-eslint/restrict-template-expressions": "off",
"@typescript-eslint/unbound-method": "off",

"no-var": "off", // TODO(bkendall): remove, allow to error.
"prefer-arrow-callback": "off", // TODO(bkendall): remove, allow to error.
},
},
{
files: ["*.spec.*"],
env: {
mocha: true,
},
rules: {},
},
],
globals: {},
parserOptions: {
ecmaVersion: "2017",
project: ["tsconfig.json", "tsconfig.dev.json"],
sourceType: "module",
warnOnUnsupportedTypeScriptVersion: false,
},
plugins: ["prettier", "@typescript-eslint", "jsdoc"],
settings: {
jsdoc: {
tagNamePreference: {
returns: "return",
},
},
},
parser: "@typescript-eslint/parser",
// dynamicImport.js is skipped in the tsbuild, we inject it manually since we
// don't want Typescript to turn the imports into requires. Ignoring as eslint
// is complaining it doesn't belong to a project.
// TODO(jamesdaniels): add this to overrides instead
ignorePatterns: [
"src/dynamicImport.js",
"scripts/webframeworks-deploy-tests/nextjs/**",
"scripts/webframeworks-deploy-tests/angular/**",
"scripts/frameworks-tests/vite-project/**",
"/src/frameworks/docs/**",
// This file is taking a very long time to lint, 2-4m
"src/emulator/auth/schema.ts",
// TODO(hsubox76): Set up a job to run eslint separately on vscode dir
"firebase-vscode/",
],
};
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist
node_modules
3 changes: 3 additions & 0 deletions .prettierrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
printWidth: 100,
};
4 changes: 2 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ export async function isUsingFirebaseJsSdk() {
if (!process.env.__FIREBASE_DEFAULTS__) return false;

try {
await import('firebase/app');
await import("firebase/app");

return true
return true;
} catch (e) {
return false;
}
Expand Down

0 comments on commit 1a91708

Please sign in to comment.