From 46d6ff4bffba4d631caa0068fe91e777a3e96ba7 Mon Sep 17 00:00:00 2001 From: Sebastian Riedel Date: Tue, 13 Jul 2021 15:30:34 +0200 Subject: [PATCH] Add eslint and prettier support --- .circleci/ci-packages.txt | 1 - .eslintrc.json | 15 +++++++++++++++ .github/workflows/javascript.yml | 23 +++++++++++++++++++++++ .gitignore | 2 ++ .prettierrc.json | 7 +++++++ Makefile | 22 ++-------------------- dependencies.yaml | 1 - dist/rpm/openQA.spec | 2 +- package.json | 20 ++++++++++++++++++++ 9 files changed, 70 insertions(+), 23 deletions(-) create mode 100644 .eslintrc.json create mode 100644 .github/workflows/javascript.yml create mode 100644 .prettierrc.json create mode 100644 package.json diff --git a/.circleci/ci-packages.txt b/.circleci/ci-packages.txt index 6a16566c2ae..c6ce2c7dec6 100644 --- a/.circleci/ci-packages.txt +++ b/.circleci/ci-packages.txt @@ -258,7 +258,6 @@ perl-YAML-PP-0.027 psmisc-23.0 python3-appdirs-1.4.3 python3-EditorConfig-0.12.2 -python3-jsbeautifier-1.6.14 python3-packaging-20.3 python3-pathspec-0.7.0 python3-pyparsing-2.2.0 diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 00000000000..20976398e9e --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,15 @@ +{ + "env": { + "browser": true, + "jquery": true, + "es2021": true + }, + "parserOptions": { + "ecmaVersion": 12 + }, + "extends": ["prettier"], + "plugins": ["prettier"], + "rules": { + "prettier/prettier": "error" + } +} diff --git a/.github/workflows/javascript.yml b/.github/workflows/javascript.yml new file mode 100644 index 00000000000..dc286dee12a --- /dev/null +++ b/.github/workflows/javascript.yml @@ -0,0 +1,23 @@ +--- +name: javascript +# yamllint disable-line rule:truthy +on: [push, pull_request] +jobs: + test: + name: Node ${{ matrix.node-version }} and ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + node-version: [16.x] + os: [ubuntu-latest] + steps: + - uses: actions/checkout@v1 + - name: Use Node ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - name: npm install + run: npm i + - name: npm run lint + run: npm run lint diff --git a/.gitignore b/.gitignore index 5ad4354a585..ed57a8f7eba 100644 --- a/.gitignore +++ b/.gitignore @@ -42,3 +42,5 @@ pool????/ container/webui/workdir base_state.json job.json +node_modules +package-lock.json diff --git a/.prettierrc.json b/.prettierrc.json new file mode 100644 index 00000000000..e055ea6d44b --- /dev/null +++ b/.prettierrc.json @@ -0,0 +1,7 @@ +{ + "arrowParens": "avoid", + "bracketSpacing": false, + "singleQuote": true, + "printWidth": 120, + "trailingComma": "none" +} diff --git a/Makefile b/Makefile index fdb801c3d55..4d415c8ae46 100644 --- a/Makefile +++ b/Makefile @@ -20,10 +20,6 @@ PROVE_ARGS ?= --trap -v $(TESTS) endif PROVE_LIB_ARGS ?= -l CONTAINER_IMG ?= openqa:latest -# python-jsbeautifier does not support reading config file -# https://github.com/beautify-web/js-beautify/issues/1074 -# Note: Keep in sync with .jsbeautifyrc -JSBEAUTIFIER_OPTS ?= --brace-style=collapse,preserve-inline TEST_PG_PATH ?= /dev/shm/tpg # TIMEOUT_M: Timeout for one retry of tests in minutes TIMEOUT_M ?= 60 @@ -264,7 +260,7 @@ prepare-and-launch-docker-to-run-tests-within: docker-test-build launch-docker-t # all additional checks not called by prove .PHONY: test-checkstyle-standalone -test-checkstyle-standalone: test-shellcheck test-yaml test-critic test-js-style +test-checkstyle-standalone: test-shellcheck test-yaml test-critic ifeq ($(CONTAINER_TEST),1) test-checkstyle-standalone: test-check-containers endif @@ -288,26 +284,12 @@ test-yaml: @# Fall back to find if there is no git, e.g. in package builds yamllint --strict $$((git ls-files "*.yml" "*.yaml" 2>/dev/null || find -name '*.y*ml') | grep -v ^dbicdh) -.PHONY: check-js-beautify -check-js-beautify: - @which js-beautify >/dev/null 2>&1 || (echo "Command 'js-beautify' not found, can not execute JavaScript beautifier" && false) - -.PHONY: test-js-style -test-js-style: check-js-beautify - @# Fall back to find if there is no git, e.g. in package builds - for i in $$(git ls-files "*.js" 2>/dev/null || find assets/javascripts/ -name '*.js'); do js-beautify ${JSBEAUTIFIER_OPTS} $$i > $$i.new; diff $$i $$i.new && rm $$i.new || exit 1; done - -.PHONY: tidy-js -tidy-js: check-js-beautify - @# Fall back to find if there is no git, e.g. in package builds - for i in $$(git ls-files "*.js" 2>/dev/null || find assets/javascripts/ -name '*.js'); do js-beautify ${JSBEAUTIFIER_OPTS} $$i > $$i.new; mv $$i.new $$i; done - .PHONY: test-check-containers test-check-containers: tools/static_check_containers .PHONY: tidy -tidy: tidy-js +tidy: tools/tidy .PHONY: test-containers-compose diff --git a/dependencies.yaml b/dependencies.yaml index ecfa8d586d3..07becb971d1 100644 --- a/dependencies.yaml +++ b/dependencies.yaml @@ -175,7 +175,6 @@ test_requires: postgresql-server: python3-setuptools: python3-yamllint: - python3-jsbeautifier: perl(App::cpanminus): perl(Mojolicious::Plugin::OAuth2): perl(Perl::Critic): diff --git a/dist/rpm/openQA.spec b/dist/rpm/openQA.spec index dc34820bc31..aaaf30a9967 100644 --- a/dist/rpm/openQA.spec +++ b/dist/rpm/openQA.spec @@ -64,7 +64,7 @@ # Do not require on this in individual sub-packages except for the devel # package. # The following line is generated from dependencies.yaml -%define test_requires %common_requires %main_requires %python_scripts_requires %worker_requires ShellCheck curl jq os-autoinst-devel perl(App::cpanminus) perl(Mojolicious::Plugin::OAuth2) perl(Perl::Critic) perl(Perl::Critic::Freenode) perl(Selenium::Remote::Driver) >= 1.23 perl(Selenium::Remote::WDKeys) perl(Test::Exception) perl(Test::Fatal) perl(Test::MockModule) perl(Test::MockObject) perl(Test::Mojo) perl(Test::Most) perl(Test::Output) perl(Test::Pod) perl(Test::Strict) perl(Test::Warnings) >= 0.029 postgresql-server python3-jsbeautifier python3-setuptools python3-yamllint +%define test_requires %common_requires %main_requires %python_scripts_requires %worker_requires ShellCheck curl jq os-autoinst-devel perl(App::cpanminus) perl(Mojolicious::Plugin::OAuth2) perl(Perl::Critic) perl(Perl::Critic::Freenode) perl(Selenium::Remote::Driver) >= 1.23 perl(Selenium::Remote::WDKeys) perl(Test::Exception) perl(Test::Fatal) perl(Test::MockModule) perl(Test::MockObject) perl(Test::Mojo) perl(Test::Most) perl(Test::Output) perl(Test::Pod) perl(Test::Strict) perl(Test::Warnings) >= 0.029 postgresql-server python3-setuptools python3-yamllint %ifarch x86_64 %define qemu qemu qemu-kvm %else diff --git a/package.json b/package.json new file mode 100644 index 00000000000..4ee2acdc75d --- /dev/null +++ b/package.json @@ -0,0 +1,20 @@ +{ + "name": "openqa", + "version": "1.0.0", + "description": "Testing Framework", + "scripts": { + "lint": "eslint \"assets/javascripts/**/*.js\"", + "fix": "eslint --fix \"assets/javascripts/**/*.js\"" + }, + "license": "GPL-2.0", + "bugs": { + "url": "https://github.com/os-autoinst/openQA/issues" + }, + "homepage": "https://github.com/os-autoinst/openQA#readme", + "devDependencies": { + "eslint": "^7.28.0", + "eslint-config-prettier": "^8.3.0", + "eslint-plugin-prettier": "^3.4.0", + "prettier": "2.3.2" + } +}