From 0fdca44b801d99e7fef20501b82e010573839132 Mon Sep 17 00:00:00 2001 From: Christoph Gysin Date: Wed, 8 Feb 2017 13:48:42 +0200 Subject: [PATCH] enable eslint for browser code Set eslint browser environment instead of listing all globals manually, and fix issues where needed. --- .../frontend/app.js | 2 +- .../app/app.js | 23 ++++++++++++------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/aws-node-auth0-custom-authorizers-api/frontend/app.js b/aws-node-auth0-custom-authorizers-api/frontend/app.js index de1012bbf..7b16fccd7 100644 --- a/aws-node-auth0-custom-authorizers-api/frontend/app.js +++ b/aws-node-auth0-custom-authorizers-api/frontend/app.js @@ -1,4 +1,4 @@ -/* global window document localStorage fetch alert */ +/* eslint-env browser */ // Fill in with your values const AUTH0_CLIENT_ID = 'your-auth0-client-id-here'; diff --git a/aws-node-single-page-app-via-cloudfront/app/app.js b/aws-node-single-page-app-via-cloudfront/app/app.js index 0aef3b732..64aadbbac 100644 --- a/aws-node-single-page-app-via-cloudfront/app/app.js +++ b/aws-node-single-page-app-via-cloudfront/app/app.js @@ -1,31 +1,38 @@ -/* eslint-disable */ +/* eslint-env browser */ +/* eslint-disable no-var */ // Renders the page based on the current URL function renderApp() { var content; + var main; + if (window.location.pathname === '/about') { - content = '
Welcome to the About page
' + content = '
Welcome to the About page
'; } else if (window.location.pathname === '/') { - content = '
Welcome Serverless Developer :)
' + content = '
Welcome Serverless Developer :)
'; } - var main = document.getElementsByTagName('main')[0]; + main = document.getElementsByTagName('main')[0]; main.innerHTML = content; } // Navigate to another URL and re-render the application function navigate(evt) { + var href; + evt.preventDefault(); - var href = evt.target.getAttribute('href'); + href = evt.target.getAttribute('href'); window.history.pushState({}, undefined, href); renderApp(); } -document.addEventListener('DOMContentLoaded', function(event) { +function render(/* event */) { // Attach the event listener once the DOM has been loaded var nav = document.getElementsByTagName('nav')[0]; - nav.addEventListener("click", navigate, false); + nav.addEventListener('click', navigate, false); // First initial App rendering renderApp(); -}); +} + +document.addEventListener('DOMContentLoaded', render);