Skip to content

Commit

Permalink
Merge pull request #35 from Oksydan/coding-standards
Browse files Browse the repository at this point in the history
Coding standards fixes and githubactions
  • Loading branch information
Oksydan authored Apr 23, 2023
2 parents 6893808 + dabd051 commit 5e9d039
Show file tree
Hide file tree
Showing 24 changed files with 2,803 additions and 733 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/list-code.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Lint code

on: [ push, pull_request ]

permissions:
contents: read

jobs:
eslint:
name: Code quality - ESLint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: '16.x'

- name: Install dependencies
run: cd ./_theme_dev && npm install

- name: Eslint action
run: cd ./_theme_dev && npm run js-lint
44 changes: 44 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: PHP tests

on: [push, pull_request]

jobs:
php-linter:
name: PHP Syntax check 7.4 => 8.1
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: PHP syntax checker 7.4
uses: prestashop/github-action-php-lint/7.4@master

- name: PHP syntax checker 8.0
uses: prestashop/github-action-php-lint/8.0@master

- name: PHP syntax checker 8.1
uses: prestashop/github-action-php-lint/8.1@master

php-cs-fixer:
name: PHP-CS-Fixer
runs-on: ubuntu-latest
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'

- name: Checkout
uses: actions/checkout@v3

- name: Cache dependencies
uses: actions/cache@v3
with:
path: vendor
key: php-${{ hashFiles('composer.lock') }}

- name: Install dependencies
run: composer install

- name: Run PHP-CS-Fixer
run: ./vendor/bin/php-cs-fixer fix --dry-run --diff --using-cache=no
9 changes: 9 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

$config = new PrestaShop\CodingStandards\CsFixer\Config();

/** @var \Symfony\Component\Finder\Finder $finder */
$finder = $config->setUsingCache(true)->getFinder();
$finder->in(__DIR__)->exclude('vendor');

return $config;
4 changes: 4 additions & 0 deletions _theme_dev/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/node_modules/
/webpack/
postcss.config.js
webpack.config.js
27 changes: 27 additions & 0 deletions _theme_dev/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module.exports = {
root: true,
env: {
browser: true,
node: false,
es6: true,
jquery: true,
},
globals: {
google: true,
document: true,
navigator: false,
window: true,
prestashop: true,
},
extends: ['airbnb-base'],
rules: {
'max-len': ['error', {code: 140}],
'no-underscore-dangle': 'off',
'no-restricted-syntax': 'off',
'no-param-reassign': 'off',
'import/no-unresolved': 'off',
},
parserOptions: {
ecmaVersion: 2022
},
}
1 change: 1 addition & 0 deletions _theme_dev/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v18.12.1
6 changes: 6 additions & 0 deletions _theme_dev/.stylelintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "stylelint-config-recommended-scss",
"rules": {
"scss/at-extend-no-missing-placeholder": null
}
}
16 changes: 15 additions & 1 deletion _theme_dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,19 @@
"label": "Theme core module",
"version": "4.0.0",
"description": "Theme core module",
"author": "Igor Stępień"
"author": "Igor Stępień",
"scripts": {
"scss-lint": "stylelint \"**/*.scss\" --fix",
"scss-lint-fix": "stylelint \"**/*.scss\" --fix",
"js-lint": "eslint -c .eslintrc.js --ext .js,.vue ./src",
"js-lint-fix": "eslint -c .eslintrc.js --ext .js,.vue ./src --fix"
},
"devDependencies": {
"stylelint": "^14.11.0",
"stylelint-config-recommended-scss": "^7.0.0",
"eslint": "^8.23.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-import": "^2.26.0",
"postcss": "^8.3.6"
}
}
101 changes: 50 additions & 51 deletions _theme_dev/src/js/listing/index.js
Original file line number Diff line number Diff line change
@@ -1,59 +1,58 @@
function initListDisplay() {
const handleClickEvent = (e) => {
const target = e.target.closest('[data-toggle-listing]');

if(target && target.dataset.toggleListing !== undefined) {
e.preventDefault();

if (target.classList.contains('active')) {
return
const handleClickEvent = (e) => {
const target = e.target.closest('[data-toggle-listing]');

if (target && target.dataset.toggleListing !== undefined) {
e.preventDefault();

if (target.classList.contains('active')) {
return;
}

const display = target.dataset.displayType;
const allButtons = document.querySelectorAll('[data-toggle-listing]');

allButtons.forEach((button) => {
button.classList.remove('active');
});

target.classList.add('active');

let requestData = {
displayType: display,
ajax: 1,
};

requestData = Object.keys(requestData).map((key) => `${encodeURIComponent(key)}=${encodeURIComponent(requestData[key])}`).join('&');

fetch(window.listDisplayAjaxUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: requestData,
})
.then((resp) => resp.text())
.then((resp) => {
try {
const response = JSON.parse(resp);

if (response.success) {
prestashop.emit('updateFacets', window.location.href);
}

const display = target.dataset.displayType;
const allButtons = document.querySelectorAll('[data-toggle-listing]');

allButtons.forEach((button) => {
button.classList.remove('active');
})

target.classList.add('active');

let requestData = {
displayType: display,
ajax: 1,
};

requestData = Object.keys(requestData).map(key => encodeURIComponent(key) + '=' + encodeURIComponent(requestData[key])).join('&')

fetch(listDisplayAjaxUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: requestData
})
.then((resp) => resp.text())
.then((resp) => {
try {
const response = JSON.parse(resp)

if (response.success) {
prestashop.emit('updateFacets', window.location.href);
}
} catch (error) {
console.log(error);
}
})
.catch((error) => {
console.error(error);
})
}
} catch (error) {
console.error(error); // eslint-disable-line no-console
}
})
.catch((error) => {
console.error(error); // eslint-disable-line no-console
});
}
};

document.addEventListener('click', handleClickEvent);
document.addEventListener('click', handleClickEvent);
}

document.addEventListener('DOMContentLoaded', () => {
initListDisplay();
initListDisplay();
});

Loading

0 comments on commit 5e9d039

Please sign in to comment.