From 06730588a6401ef604b94986fc19ea5aa97c9035 Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Tue, 23 Nov 2021 18:16:23 +0100 Subject: [mod] SearXNG JavaScript Style Guide (eslint:recommended) The SearXNG JavaScript Style Guide is a set of eslint rules [1] based on the eslint:recommended [2] rules. "extends": "eslint:recommended" The additional rules adopted from the JavaScript Standard Style [3][4]. [1] https://eslint.org/docs/rules/ [2] https://github.com/kunalgolani/eslint-config/tree/master/packages/recommended [3] https://standardjs.com/rules.html#javascript-standard-style [4] https://github.com/standard/eslint-config-standard/blob/master/.eslintrc.json Signed-off-by: Markus Heiser --- searx/static/themes/simple/gruntfile.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'searx/static/themes/simple/gruntfile.js') diff --git a/searx/static/themes/simple/gruntfile.js b/searx/static/themes/simple/gruntfile.js index 84f051f23..3602c7457 100644 --- a/searx/static/themes/simple/gruntfile.js +++ b/searx/static/themes/simple/gruntfile.js @@ -27,7 +27,8 @@ module.exports = function(grunt) { eslint: { options: { overrideConfigFile: '.eslintrc.json', - failOnError: false + failOnError: false, + fix: grunt.option('fix') }, target: [ 'svg4web.svgo.js', -- cgit v1.2.3 From 32cf24a2727c2db5b7b7187a355fd20382b5e40c Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Tue, 23 Nov 2021 20:55:38 +0100 Subject: [mod] eslint: add gruntfile.js to the files to lint Signed-off-by: Markus Heiser --- searx/static/themes/simple/gruntfile.js | 1 + 1 file changed, 1 insertion(+) (limited to 'searx/static/themes/simple/gruntfile.js') diff --git a/searx/static/themes/simple/gruntfile.js b/searx/static/themes/simple/gruntfile.js index 3602c7457..928b92d82 100644 --- a/searx/static/themes/simple/gruntfile.js +++ b/searx/static/themes/simple/gruntfile.js @@ -31,6 +31,7 @@ module.exports = function(grunt) { fix: grunt.option('fix') }, target: [ + 'gruntfile.js', 'svg4web.svgo.js', 'src/js/main/*.js', 'src/js/head/*.js', -- cgit v1.2.3 From 34f5e9c7a305d20bbebe907d3d1032ca04259537 Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Tue, 14 Dec 2021 07:31:58 +0100 Subject: [fix] eslint --fix automatically fix some of the problems reported by eslint rules:: $ ./manage nvm.bash nvm-env$ npm --prefix searx/static/themes/simple run eslint-fix Signed-off-by: Markus Heiser --- searx/static/themes/simple/gruntfile.js | 64 ++++++++++++++++----------------- 1 file changed, 32 insertions(+), 32 deletions(-) (limited to 'searx/static/themes/simple/gruntfile.js') diff --git a/searx/static/themes/simple/gruntfile.js b/searx/static/themes/simple/gruntfile.js index 928b92d82..aac1217ea 100644 --- a/searx/static/themes/simple/gruntfile.js +++ b/searx/static/themes/simple/gruntfile.js @@ -1,6 +1,6 @@ -/*jshint esversion: 6 */ +/* jshint esversion: 6 */ -module.exports = function(grunt) { +module.exports = function (grunt) { const eachAsync = require('each-async'); @@ -113,7 +113,7 @@ module.exports = function(grunt) { new (require('less-plugin-clean-css'))() ], sourceMap: true, - sourceMapURL: (name) => { const s = name.split('/'); return s[s.length - 1] + '.map';}, + sourceMapURL: (name) => { const s = name.split('/'); return s[s.length - 1] + '.map'; }, outputSourceFiles: true, }, files: { @@ -178,37 +178,37 @@ module.exports = function(grunt) { }, }); - grunt.registerMultiTask('svg2jinja', 'Create Jinja2 macro', function() { + grunt.registerMultiTask('svg2jinja', 'Create Jinja2 macro', function () { const ejs = require('ejs'), svgo = require('svgo'); const icons = {} - for(const iconName in this.data.src) { - const svgFileName = this.data.src[iconName]; - try { - const svgContent = grunt.file.read(svgFileName, { encoding: 'utf8' }) - const svgoResult = svgo.optimize(svgContent, { - path: svgFileName, - multipass: true, - plugins: [ - { - name: "removeTitle", - }, - { - name: "removeXMLNS", - }, - { - name: "addAttributesToSVGElement", - params: { - attributes: [ - { "aria-hidden": "true" } - ] - } - } - ] - }); - icons[iconName] = svgoResult.data.replace("'", "\\'"); - } catch (err) { - grunt.log.error(err); - } + for (const iconName in this.data.src) { + const svgFileName = this.data.src[iconName]; + try { + const svgContent = grunt.file.read(svgFileName, { encoding: 'utf8' }) + const svgoResult = svgo.optimize(svgContent, { + path: svgFileName, + multipass: true, + plugins: [ + { + name: "removeTitle", + }, + { + name: "removeXMLNS", + }, + { + name: "addAttributesToSVGElement", + params: { + attributes: [ + { "aria-hidden": "true" } + ] + } + } + ] + }); + icons[iconName] = svgoResult.data.replace("'", "\\'"); + } catch (err) { + grunt.log.error(err); + } } const template = `{# this file was generated by searx/static/themes/simple/gruntfile.js #} {%- set icons = { -- cgit v1.2.3 From f287787c44956a6584f78fdd9d6bf423384d1643 Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Tue, 14 Dec 2021 07:50:53 +0100 Subject: [simple theme] activate - SearXNG JavaScript Style Guide Add the 'SearXNG JavaScript Style Guide' as one quality gate in the build chain of the simple theme:: make themes.simple make themes.simple.test In the github CI the `themes.all` target enforce a `themes.simple`. BTW: Remove 'jshint' left overs from 0ee316f3d Signed-off-by: Markus Heiser --- searx/static/themes/simple/gruntfile.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'searx/static/themes/simple/gruntfile.js') diff --git a/searx/static/themes/simple/gruntfile.js b/searx/static/themes/simple/gruntfile.js index aac1217ea..46ab657e0 100644 --- a/searx/static/themes/simple/gruntfile.js +++ b/searx/static/themes/simple/gruntfile.js @@ -1,4 +1,4 @@ -/* jshint esversion: 6 */ +/* SPDX-License-Identifier: AGPL-3.0-or-later */ module.exports = function (grunt) { @@ -27,7 +27,7 @@ module.exports = function (grunt) { eslint: { options: { overrideConfigFile: '.eslintrc.json', - failOnError: false, + failOnError: true, fix: grunt.option('fix') }, target: [ @@ -268,13 +268,12 @@ module.exports = function (grunt) { grunt.loadNpmTasks('grunt-contrib-copy'); grunt.loadNpmTasks('grunt-contrib-uglify'); grunt.loadNpmTasks('grunt-image'); - grunt.loadNpmTasks('grunt-contrib-jshint'); grunt.loadNpmTasks('grunt-contrib-less'); grunt.loadNpmTasks('grunt-contrib-cssmin'); grunt.loadNpmTasks('grunt-stylelint'); grunt.loadNpmTasks('grunt-eslint'); - grunt.registerTask('test', ['jshint']); + grunt.registerTask('test', ['eslint']); grunt.registerTask('default', [ 'eslint', -- cgit v1.2.3