From c7c6dc4e671cd372e09f65bde60832fa9177e369 Mon Sep 17 00:00:00 2001 From: Veeck Date: Wed, 1 Apr 2020 21:07:50 +0200 Subject: [PATCH] Move config check into js folder, cleanup var usage --- {tests/configs => js}/check_config.js | 27 ++++++++++++--------------- package.json | 2 +- 2 files changed, 13 insertions(+), 16 deletions(-) rename {tests/configs => js}/check_config.js (72%) diff --git a/tests/configs/check_config.js b/js/check_config.js similarity index 72% rename from tests/configs/check_config.js rename to js/check_config.js index 917b6d32..f73e4bf9 100644 --- a/tests/configs/check_config.js +++ b/js/check_config.js @@ -11,11 +11,13 @@ const Linter = require("eslint").Linter; const linter = new Linter(); -const config = require(__dirname + "/../../.eslintrc.json"); -var path = require("path"); -var fs = require("fs"); -var Utils = require(__dirname + "/../../js/utils.js"); +const path = require("path"); +const fs = require("fs"); + +const rootPath = path.resolve(__dirname + "/../"); +const config = require(rootPath + "/.eslintrc.json"); +const Utils = require(rootPath + "/js/utils.js"); /* getConfigFile() * Return string with path of configuration file @@ -23,8 +25,7 @@ var Utils = require(__dirname + "/../../js/utils.js"); */ function getConfigFile() { // FIXME: This function should be in core. Do you want refactor me ;) ?, be good! - rootPath = path.resolve(__dirname + "/../../"); - var configFileName = path.resolve(rootPath + "/config/config.js"); + let configFileName = path.resolve(rootPath + "/config/config.js"); if (process.env.MM_CONFIG_FILE) { configFileName = path.resolve(process.env.MM_CONFIG_FILE); } @@ -32,7 +33,7 @@ function getConfigFile() { } function checkConfigFile() { - var configFileName = getConfigFile(); + const configFileName = getConfigFile(); // Check if file is present if (fs.existsSync(configFileName) === false) { console.error(Utils.colors.error("File not found: "), configFileName); @@ -49,7 +50,7 @@ function checkConfigFile() { // Validate syntax of the configuration file. // In case the there errors show messages and // return - console.info(Utils.colors.info("Checking file... ", configFileName)); + console.info(Utils.colors.info("Checking file... "), configFileName); // I'm not sure if all ever is utf-8 fs.readFile(configFileName, "utf-8", function (err, data) { if (err) { throw err; } @@ -58,15 +59,11 @@ function checkConfigFile() { console.log("Your configuration file doesn't contain syntax errors :)"); return true; } else { - errors = messages; - for (var idx in errors) { - error = errors[idx]; + messages.forEach(error => { console.log("Line", error.line, "col", error.column, error.message); - } + }); } }); } -if (process.env.NODE_ENV !== "test") { - checkConfigFile(); -} +checkConfigFile(); diff --git a/package.json b/package.json index faa710f2..8a0592a6 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "test:lint": "npm run test:js && npm run test:style", "test:js": "eslint *.js js/**/*.js modules/default/**/*.js clientonly/*.js serveronly/*.js translations/*.js vendor/*.js tests/**/*.js config/* --config .eslintrc.json", "test:style": "stylelint css/main.css modules/default/**/*.css --config .stylelintrc.json", - "config:check": "node tests/configs/check_config.js", + "config:check": "node js/check_config.js", "lint": "npm run lint:js && npm run lint:json && npm run lint:markdown && npm run lint:style && npm run lint:yaml", "lint:js": "eslint *.js js/**/*.js modules/default/**/*.js clientonly/*.js serveronly/*.js translations/*.js vendor/*.js tests/**/*.js config/* --config .eslintrc.json --fix", "lint:json": "jsonlint -q package.json .eslintrc.json .markdownlintrc.json .stylelintrc.json modules/default/*/translations/*.json translations/*.json vendor/package.json",