From f2e7e9226cfb2996228a1f644f529eccc2f6634f Mon Sep 17 00:00:00 2001 From: jdmedlin1 Date: Thu, 21 Aug 2025 16:15:34 -0700 Subject: [PATCH] fix(PE-1008): fixed broken linting paths and then formatted linting errors once working --- .../node-simple-server-example/package.json | 2 +- .../node-simple-server-example/src/app.js | 33 ++++++----- .../src/app.test.js | 57 +++++++++++-------- .../node-simple-server-example/src/index.js | 4 +- .../cra-template-brightsign-app/package.json | 2 +- .../template/src/server/index.js | 11 ++-- .../package.json | 2 +- templates/html5-app-template/.eslintrc | 30 ++++++++++ templates/html5-app-template/package.json | 2 +- 9 files changed, 94 insertions(+), 49 deletions(-) create mode 100644 templates/html5-app-template/.eslintrc diff --git a/examples/node-simple-server-example/package.json b/examples/node-simple-server-example/package.json index 5661efd..121ef8d 100644 --- a/examples/node-simple-server-example/package.json +++ b/examples/node-simple-server-example/package.json @@ -9,7 +9,7 @@ "build": "webpack --mode=development", "format:check": "prettier . --check --config ../.prettierrc.js --cache --cache-location=../prettiercache", "format": "prettier . --write --config ../.prettierrc.js --cache --cache-location=../prettiercache && yarn lint --fix", - "lint": "eslint --no-error-on-unmatched-pattern --config ../.eslintrc template/src/**/*.{js,jsx}", + "lint": "eslint --no-error-on-unmatched-pattern --config ../../.eslintrc src/**/*.{js,jsx}", "publish-package": "npm publish --access public" }, "repository": { diff --git a/examples/node-simple-server-example/src/app.js b/examples/node-simple-server-example/src/app.js index d013ba0..74f05cc 100644 --- a/examples/node-simple-server-example/src/app.js +++ b/examples/node-simple-server-example/src/app.js @@ -9,33 +9,38 @@ function app() { const server = http.createServer((req, res) => { // Serve device info on /api/device-info - if (req.url === '/api/device-info') { + if (req.url === "/api/device-info") { res.setHeader("Content-Type", "application/json"); const jsonResponse = JSON.stringify(di); - return res.end(jsonResponse); + res.end(jsonResponse); + return; } // Serve static files from /storage/sd/ - const filePath = path.join('/storage/sd', req.url === '/' ? 'index.html' : req.url); + const filePath = path.join( + "/storage/sd", + req.url === "/" ? "index.html" : req.url + ); fs.readFile(filePath, (err, content) => { if (err) { res.writeHead(404); - res.end('File not found'); + res.end("File not found"); return; } // Set content type based on file extension const ext = path.extname(filePath); - const contentType = { - '.html': 'text/html', - '.js': 'text/javascript', - '.css': 'text/css', - '.json': 'application/json', - '.png': 'image/png', - '.jpg': 'image/jpeg', - }[ext] || 'text/plain'; - - res.writeHead(200, { 'Content-Type': contentType }); + const contentType = + { + ".html": "text/html", + ".js": "text/javascript", + ".css": "text/css", + ".json": "application/json", + ".png": "image/png", + ".jpg": "image/jpeg", + }[ext] || "text/plain"; + + res.writeHead(200, { "Content-Type": contentType }); res.end(content); }); }); diff --git a/examples/node-simple-server-example/src/app.test.js b/examples/node-simple-server-example/src/app.test.js index f1021e7..e5d5ffa 100644 --- a/examples/node-simple-server-example/src/app.test.js +++ b/examples/node-simple-server-example/src/app.test.js @@ -1,6 +1,5 @@ const http = require("http"); -const diClass = require("@brightsign/deviceinfo"); -const main = require("./app"); +const main = require("./app.js"); describe("HTTP Server Response", () => { let server; @@ -16,35 +15,43 @@ describe("HTTP Server Response", () => { } }); - it("should respond with JSON containing mocked device info", (done) => { - http.get(`http://localhost:${port}/api/device-info`, (res) => { - expect(res.statusCode).toBe(200); - expect(res.headers["content-type"]).toBe("application/json"); + it("should respond with JSON containing mocked device info", async () => { + const response = await new Promise((resolve, reject) => { + http.get(`http://localhost:${port}/api/device-info`, (res) => { + expect(res.statusCode).toBe(200); + expect(res.headers["content-type"]).toBe("application/json"); - let data = ""; - res.on("data", (chunk) => { - data += chunk; - }); - res.on("end", () => { - const receivedData = JSON.parse(data); + let data = ""; + res.on("data", (chunk) => { + data += chunk; + }); + res.on("end", () => { + const receivedData = JSON.parse(data); - // Verify that the response contains the mocked device info - expect(receivedData.model).toBe("MockModel"); - expect(receivedData.osVersion).toBe("MockOSVersion"); - expect(receivedData.serialNumber).toBe("MockSerialNumber"); - done(); + // Verify that the response contains the mocked device info + expect(receivedData.model).toBe("MockModel"); + expect(receivedData.osVersion).toBe("MockOSVersion"); + expect(receivedData.serialNumber).toBe("MockSerialNumber"); + resolve(receivedData); + }); + }).on("error", (err) => { + reject(err); }); - }).on("error", (err) => { - done(err); }); + expect(response).toBeDefined(); }); - it("should return 404 for non-existent files", (done) => { - http.get(`http://localhost:${port}/non-existent-file.txt`, (res) => { - expect(res.statusCode).toBe(404); - done(); - }).on("error", (err) => { - done(err); + it("should return 404 for non-existent files", async () => { + await new Promise((resolve, reject) => { + http.get( + `http://localhost:${port}/non-existent-file.txt`, + (res) => { + expect(res.statusCode).toBe(404); + resolve(); + } + ).on("error", (err) => { + reject(err); + }); }); }); }); diff --git a/examples/node-simple-server-example/src/index.js b/examples/node-simple-server-example/src/index.js index 45eb46b..d6cf29e 100644 --- a/examples/node-simple-server-example/src/index.js +++ b/examples/node-simple-server-example/src/index.js @@ -1,5 +1,5 @@ -import app from "./app"; +import app from "./app.js"; app().catch((err) => { - console.error("Error running server" + err); + console.error(`Error running server: ${err}`); }); diff --git a/templates/cra-template-brightsign-app/package.json b/templates/cra-template-brightsign-app/package.json index c39f6ae..71b9b0d 100644 --- a/templates/cra-template-brightsign-app/package.json +++ b/templates/cra-template-brightsign-app/package.json @@ -20,7 +20,7 @@ "test": "jest --config jest.config.js template/src/", "format:check": "prettier . --check --config ../.prettierrc.js --cache --cache-location=../prettiercache", "format": "prettier . --write --config ../.prettierrc.js --cache --cache-location=../prettiercache && yarn lint --fix", - "lint": "eslint --no-error-on-unmatched-pattern --config ../.eslintrc template/src/**/*.{js,jsx}", + "lint": "eslint --no-error-on-unmatched-pattern --config ../../.eslintrc template/src/**/*.{js,jsx}", "publish-package": "npm publish --access public" } } diff --git a/templates/cra-template-brightsign-app/template/src/server/index.js b/templates/cra-template-brightsign-app/template/src/server/index.js index 291e12b..089144c 100644 --- a/templates/cra-template-brightsign-app/template/src/server/index.js +++ b/templates/cra-template-brightsign-app/template/src/server/index.js @@ -6,10 +6,13 @@ const app = express(); app.use(express.json()); app.use(express.static(path)); -app.use(function (req, res, next) { - res.setHeader('Access-Control-Allow-Origin', '*'); - res.setHeader('Access-Control-Allow-Headers', 'Content-Type'); - res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS'); +app.use((req, res, next) => { + res.setHeader("Access-Control-Allow-Origin", "*"); + res.setHeader("Access-Control-Allow-Headers", "Content-Type"); + res.setHeader( + "Access-Control-Allow-Methods", + "GET, POST, PUT, DELETE, OPTIONS" + ); next(); }); diff --git a/templates/cra-template-brightsign-dashboard/package.json b/templates/cra-template-brightsign-dashboard/package.json index a5f8455..fdff831 100644 --- a/templates/cra-template-brightsign-dashboard/package.json +++ b/templates/cra-template-brightsign-dashboard/package.json @@ -20,7 +20,7 @@ "test": "jest --config jest.config.js template/src/", "format:check": "prettier . --check --config ../.prettierrc.js --cache --cache-location=../prettiercache", "format": "prettier . --write --config ../.prettierrc.js --cache --cache-location=../prettiercache && yarn lint --fix", - "lint": "eslint --no-error-on-unmatched-pattern --config ../.eslintrc template/src/**/*.{js,jsx}", + "lint": "eslint --no-error-on-unmatched-pattern --config ../../.eslintrc template/src/**/*.{js,jsx}", "publish-package": "npm publish --access public" } } diff --git a/templates/html5-app-template/.eslintrc b/templates/html5-app-template/.eslintrc new file mode 100644 index 0000000..a256308 --- /dev/null +++ b/templates/html5-app-template/.eslintrc @@ -0,0 +1,30 @@ +{ + "extends": [ + "prettier" + ], + "plugins": ["prettier", "@typescript-eslint"], + "parser": "@typescript-eslint/parser", + "parserOptions": { + "ecmaVersion": 2020, + "sourceType": "module" + }, + "rules": { + "prettier/prettier": ["warn"], + "import/no-unresolved": ["off"], + "import/no-extraneous-dependencies": ["off"], + "no-console": ["off"], + "import/prefer-default-export": ["off"], + "import/extensions": ["off"], + "import/order": ["off"], + "import/newline-after-import": ["off"], + "no-use-before-define": ["off"], + "arrow-body-style": ["off"], + "eqeqeq": ["off"], + "prefer-destructuring": ["off"], + "@typescript-eslint/no-unused-vars": ["error"] + }, + "env": { + "browser": true, + "node": true + } +} \ No newline at end of file diff --git a/templates/html5-app-template/package.json b/templates/html5-app-template/package.json index 89079c8..83a7b48 100644 --- a/templates/html5-app-template/package.json +++ b/templates/html5-app-template/package.json @@ -9,7 +9,7 @@ "build:prod": "npm run clean && webpack --mode production --node-env=production", "clean": "rm -rf dist", "reinstall": "npm run clean && rm -rf node_modules && npm install", - "lint": "eslint --no-error-on-unmatched-pattern --config ../.eslintrc src/**/*.{ts,tsx}", + "lint": "eslint --no-error-on-unmatched-pattern --config .eslintrc src/**/*.{ts,tsx}", "lint:fix": "eslint --fix src --ext js,jsx,ts,tsx,json", "format:check": "prettier 'src/**/*.{js,jsx,ts,tsx,css,md,json}' --check --config ../.prettierrc.js --cache --cache-location=../prettiercache", "format": "prettier --write 'src/**/*.{js,jsx,ts,tsx,css,md,json}' --config ../.prettierrc.js && npm run lint",