Skip to content

Commit

Permalink
Add eslint and prettier support
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jul 13, 2021
1 parent 05fed65 commit 46d6ff4
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 23 deletions.
1 change: 0 additions & 1 deletion .circleci/ci-packages.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"env": {
"browser": true,
"jquery": true,
"es2021": true
},
"parserOptions": {
"ecmaVersion": 12
},
"extends": ["prettier"],
"plugins": ["prettier"],
"rules": {
"prettier/prettier": "error"
}
}
23 changes: 23 additions & 0 deletions .github/workflows/javascript.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,5 @@ pool????/
container/webui/workdir
base_state.json
job.json
node_modules
package-lock.json
7 changes: 7 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"arrowParens": "avoid",
"bracketSpacing": false,
"singleQuote": true,
"printWidth": 120,
"trailingComma": "none"
}
22 changes: 2 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion dependencies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ test_requires:
postgresql-server:
python3-setuptools:
python3-yamllint:
python3-jsbeautifier:
perl(App::cpanminus):
perl(Mojolicious::Plugin::OAuth2):
perl(Perl::Critic):
Expand Down
2 changes: 1 addition & 1 deletion dist/rpm/openQA.spec
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}

0 comments on commit 46d6ff4

Please sign in to comment.