Skip to content

Commit

Permalink
Tools: Updated linting of TypeScript source code.
Browse files Browse the repository at this point in the history
  • Loading branch information
bre1470 authored and TorsteinHonsi committed May 8, 2019
1 parent df5711b commit 54badb8
Show file tree
Hide file tree
Showing 12 changed files with 136 additions and 52 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ samples/highcharts/common-js/**/*.js
samples/cloud/**/**/*.js
samples/static/*.js
tools/eslint-plugin-highcharts/node_modules/**
js/parts/Globals.js
test/test-controller.js
test/test-template.js
test/test-utilities.js
1 change: 1 addition & 0 deletions js/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
parts/Globals.js
21 changes: 10 additions & 11 deletions js/parts/Globals.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
/* *
* (c) 2010-2019 Torstein Honsi
*
* License: www.highcharts.com/license
* (c) 2010-2019 Torstein Honsi
*
* SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY!
*/
/* eslint-disable */
* License: www.highcharts.com/license
*
* !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
*
* */
'use strict';
/* globals window */
/**
* Reference to the global SVGElement class as a workaround for a name conflict
* in the Highcharts namespace.
Expand All @@ -15,8 +18,6 @@
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/SVGElement
*/
'use strict';
/* global win, window */
// glob is a temporary fix to allow our es-modules to work.
var glob = typeof win === 'undefined' ?
(typeof window !== 'undefined' ? window : {}) :
Expand All @@ -31,7 +32,7 @@ var Highcharts = {
deg2rad: Math.PI * 2 / 360,
doc: doc,
hasBidiBug: hasBidiBug,
hasTouch: doc && doc.documentElement.ontouchstart !== undefined,
hasTouch: doc && typeof doc.documentElement.ontouchstart !== 'undefined',
isMS: isMS,
isWebKit: userAgent.indexOf('AppleWebKit') !== -1,
isFirefox: isFirefox,
Expand All @@ -45,9 +46,7 @@ var Highcharts = {
svg: svg,
win: glob,
marginNames: ['plotTop', 'marginRight', 'marginBottom', 'plotLeft'],
noop: function () {
return undefined;
},
noop: function () { },
/**
* An array containing the current chart objects in the page. A chart's
* position in the array is preserved throughout the page's lifetime. When
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,15 @@
"husky": {
"hooks": {
"commit-msg": "node tools/validate-commit-msg.js ${HUSKY_GIT_PARAMS}",
"pre-commit": "lint-staged && gulp scripts && gulp test"
"pre-commit": "npx lint-staged && npx gulp lint-ts && npx gulp scripts && npx gulp test"
}
},
"devDependencies": {
"@babel/core": "^7.3.4",
"@babel/preset-env": "^7.3.4",
"@types/jquery": "^3.3.29",
"@types/qunit": "^2.5.4",
"@typescript-eslint/eslint-plugin": "^1.7.0",
"acorn": "^6.1.1",
"aws-sdk": "^2.432.0",
"babel-plugin-transform-es2015-arrow-functions": "^6.8.0",
Expand All @@ -56,7 +57,7 @@
"closurecompiler": "^1.6.1",
"colors": "^1.3.3",
"cross-env": "^5.2.0",
"dtslint": "^0.5.9",
"dtslint": "^0.7.1",
"eslint": "^5.16.0",
"eslint-config-eslint": "^5.0.1",
"eslint-plugin-highcharts": "file:tools/eslint-plugin-highcharts",
Expand Down Expand Up @@ -89,7 +90,7 @@
"lint-staged": "^4.2.3",
"log-update": "^2.3.0",
"lolex": "^2.7.5",
"marked": "^0.6.1",
"marked": "^0.6.2",
"mkdirp": "^0.5.1",
"node-sass": "^4.11.0",
"pixelmatch": "^4.0.2",
Expand Down
66 changes: 66 additions & 0 deletions tools/gulptasks/lib/git.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright (C) Highsoft AS
*/

/* eslint no-use-before-define: 0 */

/* *
*
* Constants
*
* */

const PORCELAN_REGEXP = /([ACDMRU\?\! ])([ACDMRU\?\! ]) ([\.\/\w]+)/;

/* *
*
* Functions
*
* */

/**
* Returns the list of modified files, that are either staged or unstaged.
*
* @return {Promise<Array<[string,string,string]>>}
* Promise to keep with results
*/
function getStatus() {

const ChildProcess = require('child_process');

return new Promise((resolve, reject) => {

ChildProcess.exec(
'git status --porcelain',
(error, stdout) => {

if (error) {
reject(error);
return;
}

resolve((
stdout
.split('\n')
.map(line => PORCELAN_REGEXP.exec(line))
.filter(match => !!match)
.map(match => (
(new Array(...match))
.slice(1)
.map(column => column.trim())
))
));
}
);
});
}

/* *
*
* Exports
*
* */

module.exports = {
getStatus
};
16 changes: 12 additions & 4 deletions tools/gulptasks/lib/process.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,15 @@ const CONFIG_FILE = Path.join(
* Outputs stdout to the console.
*
* @param {string} command
* Command to execute in terminal
* Command to execute in terminal
*
* @param {boolean} silent
* Silents the command output to stdout
*
* @return {Promise<string>}
* Promise to keep with all terminal output
*/
function exec(command) {
function exec(command, silent) {

const ChildProcess = require('child_process');

Expand All @@ -57,12 +60,17 @@ function exec(command) {
LogLib.failure(error);
reject(error);
} else {
LogLib.success('Command finished: ' + command);
LogLib.success(
(silent ? 'Command finished (silent):' : 'Command finished:'),
command
);
resolve(stdout);
}
});

cli.stdout.on('data', data => process.stdout.write(data));
if (!silent) {
cli.stdout.on('data', data => process.stdout.write(data));
}
});
}

Expand Down
15 changes: 4 additions & 11 deletions tools/gulptasks/lint-ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const Gulp = require('gulp');
*
* */

const SOURCE_GLOB = 'ts/masters/tsconfig-*.json';
const SOURCE_GLOB = '**/*.ts';

/* *
*
Expand All @@ -26,23 +26,16 @@ const SOURCE_GLOB = 'ts/masters/tsconfig-*.json';
*/
function task() {

const Glob = require('glob');
const LogLib = require('./lib/log');
const ProcessLib = require('./lib/process');

return new Promise((resolve, reject) => {

LogLib.message('Linting [', SOURCE_GLOB, ']...');

Promise
.all(
Glob
.sync(SOURCE_GLOB)
.map(file => ProcessLib.exec(
'npx tslint --project ' + file
))
)
.then(() => LogLib.success('Finished linting', SOURCE_GLOB))
ProcessLib
.exec('cd ts && npx eslint ' + SOURCE_GLOB)
.then(() => LogLib.success('Finished linting'))
.then(resolve)
.catch(reject);
});
Expand Down
13 changes: 10 additions & 3 deletions tools/gulptasks/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ const GFX_DIRECTORY = 'gfx';

const JS_DIRECTORY = 'js';

const TS_DIRECTORY = 'ts';

/* *
*
* Functions
Expand All @@ -46,12 +48,14 @@ function saveRun() {
const latestJSHash = FSLib.getDirectoryHash(
JS_DIRECTORY, true, StringLib.removeComments
);
const latestTSHash = FSLib.getDirectoryHash(TS_DIRECTORY, true);

const configuration = {
latestCodeHash,
latestCSSHash,
latestGFXHash,
latestJSHash
latestJSHash,
latestTSHash
};

FS.writeFileSync(CONFIGURATION_FILE, JSON.stringify(configuration));
Expand All @@ -74,7 +78,8 @@ function shouldRun() {
latestCodeHash: '',
latestCSSHash: '',
latestGFXHash: '',
latestJSHash: ''
latestJSHash: '',
latestTSHash: ''
};

if (FS.existsSync(CONFIGURATION_FILE)) {
Expand All @@ -93,11 +98,13 @@ function shouldRun() {
const latestJSHash = FSLib.getDirectoryHash(
JS_DIRECTORY, true, StringLib.removeComments
);
const latestTSHash = FSLib.getDirectoryHash(TS_DIRECTORY, true);

if (latestCodeHash === configuration.latestCodeHash &&
latestCSSHash === configuration.latestCSSHash &&
latestGFXHash === configuration.latestGFXHash &&
latestJSHash === configuration.latestJSHash
latestJSHash === configuration.latestJSHash &&
latestTSHash === configuration.latestTSHash
) {

LogLib.success(
Expand Down
12 changes: 12 additions & 0 deletions ts/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json"
},
"plugins": ["@typescript-eslint"],
"rules": {
"no-unused-expressions": 0,
"node/no-unsupported-features": 0,
"object-shorthand": 0
}
}
File renamed without changes.
File renamed without changes.
36 changes: 16 additions & 20 deletions ts/parts/Globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,22 @@
*
* License: www.highcharts.com/license
*
* !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY! !!!!!!!
* !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
*
* */

/* eslint-disable */
'use strict';

declare global {
interface IGlobalHighcharts {
[key: string]: any;
}
type GlobalSVGElement = SVGElement;
}

declare const win: Window;

/* globals window */

/**
* Reference to the global SVGElement class as a workaround for a name conflict
Expand All @@ -20,19 +31,6 @@
* @see https://developer.mozilla.org/en-US/docs/Web/API/SVGElement
*/

declare global {
interface GlobalHighcharts {
[key: string]: any;
}
type GlobalSVGElement = SVGElement;
}

'use strict';

declare const win: Window;

/* global win, window */

// glob is a temporary fix to allow our es-modules to work.
var glob = typeof win === 'undefined' ?
(typeof window !== 'undefined' ? window : {} as Window) :
Expand All @@ -53,13 +51,13 @@ var glob = typeof win === 'undefined' ?
parseInt(userAgent.split('Firefox/')[1], 10) < 4 // issue #38
);

var Highcharts: GlobalHighcharts = {
var Highcharts: IGlobalHighcharts = {
product: '@product.name@',
version: '@product.version@',
deg2rad: Math.PI * 2 / 360,
doc: doc,
hasBidiBug: hasBidiBug,
hasTouch: doc && doc.documentElement.ontouchstart !== undefined,
hasTouch: doc && typeof doc.documentElement.ontouchstart !== 'undefined',
isMS: isMS,
isWebKit: userAgent.indexOf('AppleWebKit') !== -1,
isFirefox: isFirefox,
Expand All @@ -73,9 +71,7 @@ var Highcharts: GlobalHighcharts = {
svg: svg,
win: glob,
marginNames: ['plotTop', 'marginRight', 'marginBottom', 'plotLeft'],
noop: function () {
return undefined;
},
noop: function () {},
/**
* An array containing the current chart objects in the page. A chart's
* position in the array is preserved throughout the page's lifetime. When
Expand Down

0 comments on commit 54badb8

Please sign in to comment.