Skip to content

Commit

Permalink
js lint fix errors
Browse files Browse the repository at this point in the history
  • Loading branch information
yuriipavlov committed Nov 26, 2023
1 parent c6f3f6f commit bea4d10
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 154 deletions.
14 changes: 0 additions & 14 deletions assets/src/js/_app.js

This file was deleted.

File renamed without changes.
9 changes: 9 additions & 0 deletions assets/src/js/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require('bootstrap'); // full bootstrap
// require('bootstrap/js/src/button'); // single bootstrap component

/*
$(document).ready(() => {
new Theme();
new headerMenu();
});
*/
37 changes: 0 additions & 37 deletions assets/src/js/front-components/_header-menu.js

This file was deleted.

124 changes: 63 additions & 61 deletions assets/src/js/front-components/_theme.js
Original file line number Diff line number Diff line change
@@ -1,63 +1,65 @@
import $ from 'jquery';

export default class Theme {
/**
Constructor
**/
constructor() {
this.build();
this.events()
}

/**
Build page elements, plugins init
**/
build() {
this.setupHeader();
}

/**
Set page events
**/
events() {

}

/**
* Setup Header
**/
setupHeader() {


}

/** Check for mobile device **/
isMobile() {
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
}

stringToBoolean(string) {

switch (string) {
case "true":
case "yes":
case "1":
return true;
case "false":
case "no":
case "0":
case null:
case '':
return false;
default:
return Boolean(string);
}
}

/** Check email address **/
isValidEmailAddress(emailAddress) {
const pattern = new RegExp(/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i);
return pattern.test(emailAddress);
}

/**
Constructor
*/
constructor() {
this.build();
this.events();
}

/**
Build page elements, plugins init
*/
build() {
this.setupHeader();
}

/**
Set page events
*/
events() {

}

/**
* Setup Header
*/
setupHeader() {

}

/** Check for mobile device */
isMobile() {
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
navigator.userAgent);
}

stringToBoolean(string) {

switch (string) {
case 'true':
case 'yes':
case '1':
return true;
case 'false':
case 'no':
case '0':
case null:
case '':
return false;
default:
return Boolean(string);
}
}

/**
* Check email address
* @param {string} emailAddress
*/
isValidEmailAddress(emailAddress) {
const pattern = new RegExp(
/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i);
return pattern.test(emailAddress);
}

}
7 changes: 5 additions & 2 deletions blocks/_StarterBlock/src/Handlers/FrontendModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,21 @@ export default class FrontendModule {
this.starterBlock = starterBlock;
this.someThingInner = starterBlock.querySelector(".some-class");

// eslint-disable-next-line no-console
console.log('StarterBlock FrontendModule loaded');

this.doSomething(this.someThingInner)
this.doSomething(this.someThingInner);

}

doSomething(someThingInner) {
const self = this;

// Using 'self' to access the class instance inside the event listener
// eslint-disable-next-line no-console
console.log(self.starterBlock);
console.log('StarterBlock FrontendModule Something happened');
// eslint-disable-next-line no-console
console.log('StarterBlock FrontendModule Something happened' + someThingInner);
// Do something
}

Expand Down
1 change: 0 additions & 1 deletion blocks/_StarterBlock/src/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import FrontendModule from "./Handlers/FrontendModule";
(function () {
"use strict";


/**
* Init block on load
*/
Expand Down
3 changes: 3 additions & 0 deletions mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"/assets/build/js/app.js": "/assets/build/js/app.js",
"/assets/build/js/front-components/_theme.js": "/assets/build/js/front-components/_theme.js",
"/blocks/Row/build/index.js": "/blocks/Row/build/index.js",
"/blocks/News/build/index.js": "/blocks/News/build/index.js",
"/blocks/News/build/_edit.js": "/blocks/News/build/_edit.js",
"/blocks/Container/build/index.js": "/blocks/Container/build/index.js",
"/blocks/Column/build/index.js": "/blocks/Column/build/index.js",
"/blocks/Row/build/editor.css": "/blocks/Row/build/editor.css",
Expand Down
76 changes: 37 additions & 39 deletions webpack.mix.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
*/
const mix = require('laravel-mix');
const glob = require('glob');
const {CleanWebpackPlugin} = require('clean-webpack-plugin');

/**
* Setup options
Expand Down Expand Up @@ -38,8 +37,9 @@ mix.disableNotifications();
* ]
*/
if (!mix.inProduction()) {
const ESLintPlugin = require('eslint-webpack-plugin');
const StylelintPlugin = require('stylelint-webpack-plugin');
const {CleanWebpackPlugin} = require('clean-webpack-plugin');
const ESLintWebpackPlugin = require('eslint-webpack-plugin');
const StylelintWebpackPlugin = require('stylelint-webpack-plugin');

mix.sourceMaps().webpackConfig({
devtool: 'inline-source-map',
Expand All @@ -63,14 +63,14 @@ if (!mix.inProduction()) {
/**
* Code QA
*/
new ESLintPlugin({
new ESLintWebpackPlugin({
fix: false,
extensions: ['js', 'jsx'],
overrideConfigFile: '.eslintrc.json',
failOnError: false,
cache: true,
}),
new StylelintPlugin({
new StylelintWebpackPlugin({
fix: false,
extensions: ['scss'],
configFile: '.stylelintrc.json',
Expand All @@ -94,8 +94,10 @@ if (!mix.inProduction()) {
* Block folders that names start with '_' will be ignored too.
* Example, '_StarterBlock' - should not be registered
*/
const allAssets = glob.sync('assets/src/**/!(_)*.@(scss|js|jsx)')
.concat(glob.sync('blocks/!(_)**/src/!(_)*.@(scss|js|jsx)'));
const allAssets = glob.sync(
'{assets/src/**/!(_)*.scss,assets/src/**/*.{js,jsx}}')
.concat(
glob.sync('{blocks/!(_)**/src/!(_)*.scss,blocks/!(_)**/src/*.{js,jsx}}'));

/**
* Run Preprocessing
Expand All @@ -119,49 +121,20 @@ allAssets.forEach(assetPath => {
});

/**
* Stop here if production
* BrowserSync runs on dev mode only
*/
if (mix.inProduction()) {
console.log('Cannot run BrowserSync in production mode.');
return;
}

console.log('APP_NAME', process.env.APP_NAME);

/**
* BrowserSync
*/
const appProtocol = process.env.APP_PROTOCOL;
const appDomain = process.env.APP_DOMAIN;

let appPort = '';

if (appProtocol === 'https') {
appPort = process.env.APP_HTTPS_PORT;
} else {
appPort = process.env.APP_HTTP_PORT;
}

let appUrl = appProtocol + '://' + appDomain;

if (appPort !== '80' && appPort !== '443') {
appUrl += ':' + appPort;
}

const hostIp = process.env.HOST_IP || 'undefined';

mix.browserSync({
/**
* Proxying to nginx container with alias APP_DOMAIN
* Proxy should be the same as WP_SITEURL in wp-config.php
*/
proxy: appUrl,
proxy: getAppUrl(),
/**
* Set external host network IP.
* If hostIp is undefined, just find your local network IP in your system
* and use it in your other devices browser to sync with BrowserSync.
*/
host: hostIp,
host: getHostIp(),
port: 3000,
open: false,
files: [
Expand All @@ -170,3 +143,28 @@ mix.browserSync({
'**/src/**/*.@(scss|js|jsx)',
],
});

function getAppUrl() {
const appProtocol = process.env.APP_PROTOCOL;
const appDomain = process.env.APP_DOMAIN;

let appPort = '';

if (appProtocol === 'https') {
appPort = process.env.APP_HTTPS_PORT;
} else {
appPort = process.env.APP_HTTP_PORT;
}

let appUrl = appProtocol + '://' + appDomain;

if (appPort !== '80' && appPort !== '443') {
appUrl += ':' + appPort;
}

return appUrl;
}

function getHostIp() {
return process.env.HOST_IP || 'undefined';
}

0 comments on commit bea4d10

Please sign in to comment.