Skip to content

Commit

Permalink
Add func-names ESLint rule (#1420)
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky authored Oct 21, 2020
1 parent 2eef857 commit 581a35d
Show file tree
Hide file tree
Showing 85 changed files with 231 additions and 130 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module.exports = {
'default-case': 2,
'default-case-last': 2,
'func-name-matching': [2, { considerPropertyDescriptor: true }],
'func-names': [2, 'as-needed'],
'max-classes-per-file': 2,
'max-params': [2, { max: 4 }],
'multiline-comment-style': [2, 'separate-lines'],
Expand Down
8 changes: 4 additions & 4 deletions site/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ const { ensureFilePathAsync, removeRecursiveAsync } = require('./fs')
const watcher = sane(config.docs.srcPath, { glob: ['**/*.md'] })

/* Watch Files */
watcher.on('ready', function () {
watcher.on('ready', function onReady() {
console.log(`Watching ${config.docs.srcPath} files for changes`)
})

watcher.on('change', async function (filepath) {
watcher.on('change', async function onChange(filepath) {
console.log('file changed', filepath)
await syncFile(filepath)
})

watcher.on('add', async function (filepath) {
watcher.on('add', async function onAdd(filepath) {
console.log('file added')
await syncFile(filepath)
})

watcher.on('delete', async function (filepath) {
watcher.on('delete', async function onDelete(filepath) {
console.log('file deleted', filepath)
await deleteFile(filepath)
console.log('File deletion complete')
Expand Down
2 changes: 1 addition & 1 deletion src/commands/dev/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async function startFrameworkServer({ settings, log, exit }) {
})

await new Promise((resolve) => {
server.start(function () {
server.start(function onListening() {
log(`\n${NETLIFYDEVLOG} Server listening to`, settings.frameworkPort)
resolve()
})
Expand Down
2 changes: 1 addition & 1 deletion src/detectors/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ requires a global install: https://github.com/GitbookIO/gitbook/blob/master/docs

```js
const { hasRequiredDeps, hasRequiredFiles, getYarnOrNPMCommand, scanScripts } = require('./utils/jsdetect')
module.exports = function () {
module.exports = function detector() {
// REQUIRED FILES
if (!hasRequiredFiles(['README.md', 'SUMMARY.md'])) return false
// // REQUIRED DEPS
Expand Down
2 changes: 1 addition & 1 deletion src/detectors/angular.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { hasRequiredDeps, hasRequiredFiles, getYarnOrNPMCommand, scanScripts } = require('./utils/jsdetect')

module.exports = function () {
module.exports = function detector() {
// REQUIRED FILES
if (!hasRequiredFiles(['package.json'])) return false
if (!hasRequiredFiles(['angular.json'])) return false
Expand Down
2 changes: 1 addition & 1 deletion src/detectors/brunch.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { hasRequiredDeps, hasRequiredFiles, getYarnOrNPMCommand, scanScripts } = require('./utils/jsdetect')
module.exports = function () {
module.exports = function detector() {
// REQUIRED FILES
if (!hasRequiredFiles(['package.json', 'brunch-config.js'])) return false
// REQUIRED DEPS
Expand Down
2 changes: 1 addition & 1 deletion src/detectors/create-react-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { hasRequiredDeps, hasRequiredFiles, getYarnOrNPMCommand, scanScripts } =
//
// detection logic - artificial intelligence!
//
module.exports = function () {
module.exports = function detector() {
// REQUIRED FILES
if (!hasRequiredFiles(['package.json'])) return false
// REQUIRED DEPS
Expand Down
2 changes: 1 addition & 1 deletion src/detectors/docusaurus.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { hasRequiredDeps, hasRequiredFiles, getYarnOrNPMCommand, scanScripts } = require('./utils/jsdetect')
module.exports = function () {
module.exports = function detector() {
// REQUIRED FILES
if (!hasRequiredFiles(['package.json'])) return false

Expand Down
2 changes: 1 addition & 1 deletion src/detectors/eleventy.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { hasRequiredDeps, hasRequiredFiles } = require('./utils/jsdetect')

module.exports = function () {
module.exports = function detector() {
// REQUIRED FILES
if (
!hasRequiredFiles(['package.json', '.eleventy.js']) &&
Expand Down
2 changes: 1 addition & 1 deletion src/detectors/ember.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { hasRequiredDeps, hasRequiredFiles, getYarnOrNPMCommand, scanScripts } = require('./utils/jsdetect')

module.exports = function () {
module.exports = function detector() {
// REQUIRED FILES
if (!hasRequiredFiles(['package.json'])) return false
if (!hasRequiredFiles(['ember-cli-build.js'])) return false
Expand Down
2 changes: 1 addition & 1 deletion src/detectors/expo.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { hasRequiredDeps, hasRequiredFiles, getYarnOrNPMCommand, scanScripts } = require('./utils/jsdetect')
module.exports = function () {
module.exports = function detector() {
// REQUIRED FILES
if (!hasRequiredFiles(['package.json', 'app.json'])) return false
// REQUIRED DEPS
Expand Down
2 changes: 1 addition & 1 deletion src/detectors/gatsby.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { hasRequiredDeps, hasRequiredFiles, getYarnOrNPMCommand, scanScripts } = require('./utils/jsdetect')
module.exports = function () {
module.exports = function detector() {
// REQUIRED FILES
if (!hasRequiredFiles(['package.json', 'gatsby-config.js'])) return false
// REQUIRED DEPS
Expand Down
2 changes: 1 addition & 1 deletion src/detectors/gridsome.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { hasRequiredDeps, hasRequiredFiles, getYarnOrNPMCommand, scanScripts } = require('./utils/jsdetect')
module.exports = function () {
module.exports = function detector() {
// REQUIRED FILES
if (!hasRequiredFiles(['package.json', 'gridsome.config.js'])) return false
// REQUIRED DEPS
Expand Down
2 changes: 1 addition & 1 deletion src/detectors/hexo.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { hasRequiredDeps, hasRequiredFiles, getYarnOrNPMCommand, scanScripts } = require('./utils/jsdetect')
module.exports = function () {
module.exports = function detector() {
// REQUIRED FILES
if (!hasRequiredFiles(['package.json', '_config.yml'])) return false
// REQUIRED DEPS
Expand Down
2 changes: 1 addition & 1 deletion src/detectors/hugo.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { existsSync } = require('fs')

module.exports = function () {
module.exports = function detector() {
if (!existsSync('config.toml') && !existsSync('config.yaml')) {
return false
}
Expand Down
2 changes: 1 addition & 1 deletion src/detectors/jekyll.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { existsSync } = require('fs')

module.exports = function () {
module.exports = function detector() {
if (!existsSync('_config.yml')) {
return false
}
Expand Down
2 changes: 1 addition & 1 deletion src/detectors/middleman.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { existsSync } = require('fs')

module.exports = function () {
module.exports = function detector() {
if (!existsSync('config.rb')) {
return false
}
Expand Down
2 changes: 1 addition & 1 deletion src/detectors/next.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { hasRequiredDeps, hasRequiredFiles, getYarnOrNPMCommand, scanScripts } = require('./utils/jsdetect')
module.exports = function () {
module.exports = function detector() {
// REQUIRED FILES
if (!hasRequiredFiles(['package.json'])) return false
// REQUIRED DEPS
Expand Down
2 changes: 1 addition & 1 deletion src/detectors/nuxt.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { hasRequiredDeps, hasRequiredFiles, getYarnOrNPMCommand, scanScripts } = require('./utils/jsdetect')

module.exports = function () {
module.exports = function detector() {
// REQUIRED FILES
if (!hasRequiredFiles(['package.json'])) return false
// REQUIRED DEPS
Expand Down
2 changes: 1 addition & 1 deletion src/detectors/parcel.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { hasRequiredDeps, hasRequiredFiles, getYarnOrNPMCommand, scanScripts } = require('./utils/jsdetect')

module.exports = function () {
module.exports = function detector() {
/* REQUIRED FILES */
if (!hasRequiredFiles(['package.json'])) return false

Expand Down
2 changes: 1 addition & 1 deletion src/detectors/phenomic.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { hasRequiredDeps, hasRequiredFiles, getYarnOrNPMCommand, scanScripts } = require('./utils/jsdetect')
module.exports = function () {
module.exports = function detector() {
// REQUIRED FILES
if (!hasRequiredFiles(['package.json'])) return false
// REQUIRED DEPS
Expand Down
2 changes: 1 addition & 1 deletion src/detectors/quasar-v0.17.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { hasRequiredDeps, hasRequiredFiles, getYarnOrNPMCommand, scanScripts } = require('./utils/jsdetect')

module.exports = function () {
module.exports = function detector() {
// REQUIRED FILES
if (!hasRequiredFiles(['package.json'])) return false
// REQUIRED DEPS
Expand Down
2 changes: 1 addition & 1 deletion src/detectors/quasar.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { hasRequiredDeps, hasRequiredFiles, getYarnOrNPMCommand, scanScripts } = require('./utils/jsdetect')

module.exports = function () {
module.exports = function detector() {
// REQUIRED FILES
if (!hasRequiredFiles(['package.json'])) return false
// REQUIRED DEPS
Expand Down
2 changes: 1 addition & 1 deletion src/detectors/react-static.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { hasRequiredDeps, hasRequiredFiles, getYarnOrNPMCommand, scanScripts } = require('./utils/jsdetect')
module.exports = function () {
module.exports = function detector() {
// REQUIRED FILES
if (!hasRequiredFiles(['package.json', 'static.config.js'])) return false
// REQUIRED DEPS
Expand Down
2 changes: 1 addition & 1 deletion src/detectors/sapper.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { hasRequiredDeps, hasRequiredFiles, getYarnOrNPMCommand, scanScripts } = require('./utils/jsdetect')

module.exports = function () {
module.exports = function detector() {
// REQUIRED FILES
if (!hasRequiredFiles(['package.json'])) return false
// REQUIRED DEPS
Expand Down
2 changes: 1 addition & 1 deletion src/detectors/stencil.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { hasRequiredDeps, hasRequiredFiles, getYarnOrNPMCommand, scanScripts } =
//
// detection logic - artificial intelligence!
//
module.exports = function () {
module.exports = function detector() {
// REQUIRED FILES
if (!hasRequiredFiles(['package.json', 'stencil.config.ts'])) return false
// REQUIRED DEPS
Expand Down
2 changes: 1 addition & 1 deletion src/detectors/svelte.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { hasRequiredDeps, hasRequiredFiles, getYarnOrNPMCommand, scanScripts } = require('./utils/jsdetect')

module.exports = function () {
module.exports = function detector() {
// REQUIRED FILES
if (!hasRequiredFiles(['package.json'])) return false
// REQUIRED DEPS
Expand Down
2 changes: 1 addition & 1 deletion src/detectors/vue.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { hasRequiredDeps, hasRequiredFiles, getYarnOrNPMCommand, scanScripts } = require('./utils/jsdetect')

module.exports = function () {
module.exports = function detector() {
// REQUIRED FILES
if (!hasRequiredFiles(['package.json'])) return false
// REQUIRED DEPS
Expand Down
2 changes: 1 addition & 1 deletion src/detectors/vuepress.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { hasRequiredDeps, hasRequiredFiles, getYarnOrNPMCommand, scanScripts } = require('./utils/jsdetect')

module.exports = function () {
module.exports = function detector() {
// REQUIRED FILES
if (!hasRequiredFiles(['package.json'])) return false
// REQUIRED DEPS
Expand Down
2 changes: 1 addition & 1 deletion src/function-builder-detectors/netlify-lambda.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { existsSync, readFileSync } = require('fs')
const execa = require('execa')

module.exports = function () {
module.exports = function handler() {
if (!existsSync('package.json')) {
return false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,6 @@ const server = new ApolloServer({
}),
})

exports.handler = server.createHandler()
const handler = server.createHandler()

module.exports = { handler }
4 changes: 3 additions & 1 deletion src/functions-templates/js/apollo-graphql/apollo-graphql.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,6 @@ const server = new ApolloServer({
resolvers,
})

exports.handler = server.createHandler()
const handler = server.createHandler()

module.exports = { handler }
4 changes: 3 additions & 1 deletion src/functions-templates/js/auth-fetch/auth-fetch.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// for a full working demo of Netlify Identity + Functions, see https://netlify-gotrue-in-react.netlify.com/

const fetch = require('node-fetch')
exports.handler = async function (event, context) {
const handler = async function (event, context) {
if (!context.clientContext && !context.clientContext.identity) {
return {
statusCode: 500,
Expand Down Expand Up @@ -31,3 +31,5 @@ exports.handler = async function (event, context) {
}
}
}

module.exports = { handler }
4 changes: 3 additions & 1 deletion src/functions-templates/js/create-user/create-user.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const fetch = require('node-fetch')

exports.handler = async (event, context) => {
const handler = async (event, context) => {
if (event.httpMethod !== 'POST') return { statusCode: 400, body: 'Must POST to this function' }

// send account information along with the POST
Expand Down Expand Up @@ -32,3 +32,5 @@ exports.handler = async (event, context) => {
body: 'success!',
}
}

module.exports = { handler }
4 changes: 3 additions & 1 deletion src/functions-templates/js/fauna-crud/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const client = new faunadb.Client({
})

/* export our lambda function as named "handler" export */
exports.handler = async (event) => {
const handler = async (event) => {
/* parse the string body into a useable JS object */
const data = JSON.parse(event.body)
console.log('Function `create` invoked', data)
Expand All @@ -34,3 +34,5 @@ exports.handler = async (event) => {
}
})
}

module.exports = { handler }
4 changes: 3 additions & 1 deletion src/functions-templates/js/fauna-crud/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const client = new faunadb.Client({
secret: process.env.FAUNADB_SERVER_SECRET,
})

exports.handler = async (event) => {
const handler = async (event) => {
const { id } = event
console.log(`Function 'delete' invoked. delete id: ${id}`)
return client
Expand All @@ -26,3 +26,5 @@ exports.handler = async (event) => {
}
})
}

module.exports = { handler }
4 changes: 3 additions & 1 deletion src/functions-templates/js/fauna-crud/fauna-crud.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
exports.handler = async (event, context) => {
const handler = async (event, context) => {
const path = event.path.replace(/\.netlify\/functions\/[^/]+/, '')
const segments = path.split('/').filter((e) => e)

Expand Down Expand Up @@ -53,3 +53,5 @@ exports.handler = async (event, context) => {
}
}
}

module.exports = { handler }
4 changes: 3 additions & 1 deletion src/functions-templates/js/fauna-crud/read-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const client = new faunadb.Client({
secret: process.env.FAUNADB_SERVER_SECRET,
})

exports.handler = async () => {
const handler = async () => {
console.log('Function `read-all` invoked')
return client
.query(q.Paginate(q.Match(q.Ref('indexes/all_items'))))
Expand All @@ -32,3 +32,5 @@ exports.handler = async () => {
}
})
}

module.exports = { handler }
4 changes: 3 additions & 1 deletion src/functions-templates/js/fauna-crud/read.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const client = new faunadb.Client({
secret: process.env.FAUNADB_SERVER_SECRET,
})

exports.handler = async (event) => {
const handler = async (event) => {
const { id } = event
console.log(`Function 'read' invoked. Read id: ${id}`)
return client
Expand All @@ -26,3 +26,5 @@ exports.handler = async (event) => {
}
})
}

module.exports = { handler }
4 changes: 3 additions & 1 deletion src/functions-templates/js/fauna-crud/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const client = new faunadb.Client({
secret: process.env.FAUNADB_SERVER_SECRET,
})

exports.handler = async (event) => {
const handler = async (event) => {
const data = JSON.parse(event.body)
const { id } = event
console.log(`Function 'update' invoked. update id: ${id}`)
Expand All @@ -27,3 +27,5 @@ exports.handler = async (event) => {
}
})
}

module.exports = { handler }
Loading

0 comments on commit 581a35d

Please sign in to comment.