Skip to content

Commit

Permalink
Merge branch 'tl-eslintsupport' of github.com:FirebasePrivate/firebas…
Browse files Browse the repository at this point in the history
…e-tools into tl-eslintsupport
  • Loading branch information
tinaliang committed Dec 14, 2017
2 parents 64ac351 + 56ea37a commit b89991d
Show file tree
Hide file tree
Showing 4 changed files with 168 additions and 3 deletions.
25 changes: 22 additions & 3 deletions lib/init/features/functions/javascript.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,36 @@
'use strict';

var _ = require('lodash');
var fs = require('fs');
var path = require('path');

var npmDependencies = require('./npm-dependencies');
var prompt = require('../../../prompt');

var TEMPLATE_ROOT = path.resolve(__dirname, '../../../../templates/init/functions/javascript/');
var INDEX_TEMPLATE = fs.readFileSync(path.join(TEMPLATE_ROOT, 'index.js'), 'utf8');
var PACKAGE_TEMPLATE = fs.readFileSync(path.join(TEMPLATE_ROOT, 'package.json'), 'utf8');
var PACKAGE_LINTING_TEMPLATE = fs.readFileSync(path.join(TEMPLATE_ROOT, 'package.lint.json'), 'utf8');
var PACKAGE_NO_LINTING_TEMPLATE = fs.readFileSync(path.join(TEMPLATE_ROOT, 'package.nolint.json'), 'utf8');
var ESLINT_TEMPLATE = fs.readFileSync(path.join(TEMPLATE_ROOT, 'eslint.json'), 'utf8');

module.exports = function(setup, config) {
return config.askWriteProjectFile('functions/package.json', PACKAGE_TEMPLATE).then(function() {
return config.askWriteProjectFile('functions/index.js', INDEX_TEMPLATE);
return prompt(setup.functions, [
{
name: 'lint',
type: 'confirm',
message: 'Do you want to use ESLint to catch probable bugs and enforce style?',
default: true
}
]).then(function() {
if (setup.functions.lint) {
_.set(setup, 'config.functions.predeploy', 'npm --prefix functions run lint');
return config.askWriteProjectFile('functions/package.json', PACKAGE_LINTING_TEMPLATE).then(function() {
config.askWriteProjectFile('functions/.eslintrc.json', ESLINT_TEMPLATE);
});
}
return config.askWriteProjectFile('functions/package.json', PACKAGE_NO_LINTING_TEMPLATE);
}).then(function() {
return config.askWriteProjectFile('functions/src/index.js', INDEX_TEMPLATE);
}).then(function() {
return npmDependencies.askInstallDependencies(setup, config);
});
Expand Down
125 changes: 125 additions & 0 deletions templates/init/functions/javascript/eslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
{
"parserOptions": {
// Required for certain syntax usages
"ecmaVersion": 6
},
"plugins": [
"promise"
],
"extends": "eslint:recommended",
"rules": {
// Removed rule "disallow the use of console" from recommended eslint rules
"no-console": "off",

// Removed rule "disallow multiple spaces in regular expressions" from recommended eslint rules
"no-regex-spaces": "off",

// Removed rule "disallow the use of debugger" from recommended eslint rules
"no-debugger": "off",

// Removed rule "disallow unused variables" from recommended eslint rules
"no-unused-vars": "off",

// Removed rule "disallow mixed spaces and tabs for indentation" from recommended eslint rules
"no-mixed-spaces-and-tabs": "off",

// Removed rule "disallow the use of undeclared variables unless mentioned in /*global */ comments" from recommended eslint rules
"no-undef": "off",

// Warn against template literal placeholder syntax in regular strings
"no-template-curly-in-string": 1,

// Warn if return statements do not either always or never specify values
"consistent-return": 1,

// Warn if no return statements in callbacks of array methods
"array-callback-return": 1,

// Requre the use of === and !==
"eqeqeq": 2,

// Return inside each then() to create readable and reusable Promise chains.
"promise/always-return": 2,

// Disallow the use of alert, confirm, and prompt
"no-alert": 2,

// Disallow the use of arguments.caller or arguments.callee
"no-caller": 2,

// Disallow null comparisons without type-checking operators
"no-eq-null": 2,

// Disallow the use of eval()
"no-eval": 2,

// Warn against extending native types
"no-extend-native": 1,

// Warn against unnecessary calls to .bind()
"no-extra-bind": 1,

// Warn against unnecessary labels
"no-extra-label": 1,

// Disallow leading or trailing decimal points in numeric literals
"no-floating-decimal": 2,

// Warn against shorthand type conversions
"no-implicit-coercion": 1,

// Warn against function declarations and expressions inside loop statements
"no-loop-func": 1,

// Disallow new operators with the Function object
"no-new-func": 2,

// Warn against new operators with the String, Number, and Boolean objects
"no-new-wrappers": 1,

// Disallow throwing literals as exceptions
"no-throw-literal": 2,

// Require using Error objects as Promise rejection reasons
"prefer-promise-reject-errors": 2,

// Enforce “for” loop update clause moving the counter in the right direction
"for-direction": 2,

// Enforce return statements in getters
"getter-return": 2,

// Disallow await inside of loops
"no-await-in-loop": 2,

// Disallow comparing against -0
"no-compare-neg-zero": 2,

// Warn against catch clause parameters from shadowing variables in the outer scope
"no-catch-shadow": 1,

// Disallow identifiers from shadowing restricted names
"no-shadow-restricted-names": 2,

// Enforce return statements in callbacks of array methods
"callback-return": 2,

// Require error handling in callbacks
"handle-callback-err": 2,

// Warn against string concatenation with __dirname and __filename
"no-path-concat": 1,

// Prefer using arrow functions for callbacks
"prefer-arrow-callback": 1,

// Return inside each then() to create readable and reusable Promise chains.
"promise/always-return": 2,

//Enforces the use of catch() on un-returned promises
"promise/catch-or-return": 2,

// Warn against nested then() or catch() statements
"promise/no-nesting": 1
}
}
21 changes: 21 additions & 0 deletions templates/init/functions/javascript/package.lint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"lint": "./node_modules/.bin/eslint .",
"serve": "firebase serve --only functions",
"shell": "firebase experimental:functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"dependencies": {
"firebase-admin": "~5.4.2",
"firebase-functions": "^0.7.1"
},
"devDependencies": {
"eslint": "^4.12.0",
"eslint-plugin-promise": "^3.6.0"
},
"private": true
}

0 comments on commit b89991d

Please sign in to comment.