Skip to content

Commit

Permalink
Merge pull request #10 from highcharts/v1.0.6
Browse files Browse the repository at this point in the history
v1.0.6
  • Loading branch information
bre1470 authored Apr 9, 2021
2 parents 8bac147 + c4aa169 commit 7f3d924
Show file tree
Hide file tree
Showing 7 changed files with 938 additions and 870 deletions.
66 changes: 66 additions & 0 deletions lib/rules/no-highcharts-namespace.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* @fileoverview The global Highcharts namespace should not be used, as it makes
* type modifications difficult. Instead write declarations in `.d.ts` files
* and make use of `declare module...` in `.ts` files for further extension.
*/
'use strict';

const message = 'Do not use the global Highcharts namespace for declarations.';

//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------

module.exports = {
meta: {
docs: {
description: message,
category: 'Migration',
recommended: false
},
fixable: null, // or "code" or "whitespace"
schema: [
// fill in your schema
]
},

create: function (context) {

// variables should be defined here
const code = context.getSourceCode().lines.join('\n');

//----------------------------------------------------------------------
// Helpers
//----------------------------------------------------------------------
const program = (node) => {

const regex = /namespace (Highcharts)/g;

let match;

while (match = regex.exec(code)) {
const codeBefore = code.substr(0, regex.lastIndex - match[1].length);
const linesBefore = codeBefore.split('\n');
const line = linesBefore[linesBefore.length - 1];

context.report({
node: node,
loc: {
line: linesBefore.length,
column: line.length
},
message: message
});
}
};

//----------------------------------------------------------------------
// Public
//----------------------------------------------------------------------
return {

Program: program

};
}
};
33 changes: 15 additions & 18 deletions lib/rules/no-highcharts-object.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* @fileoverview The global Highcharts object should not be used, as it breaks
* in module mode. Instead make use of import of the Globals file as an H
* in module mode. Instead make use of import of the `Core/Globals` file as an H
* object.
*/
'use strict';

const message = 'Do not use global Highcharts object to access utility functions.';
const message = 'Do not use the global Highcharts object to access utility functions.';

//------------------------------------------------------------------------------
// Rule Definition
Expand Down Expand Up @@ -34,37 +34,34 @@ module.exports = {
//----------------------------------------------------------------------
const program = (node) => {

const regex1 = /import Highcharts from/;

if (regex1.test(code)) {
if (/import Highcharts from/.test(code)) {
return;
}

const regex2 = /Highcharts\.(?:[a-z])/g;
const regex3 = /^\s+(?:\/\/|\/\*|\*)/;
const regex4 = /\: |as |[\|\<'"]$/;
const regex = /Highcharts\.[a-z]/g;

let match;

while (regex2.exec(code, regex2.lastIndex)) {
while (match = regex.exec(code)) {

const codeBefore = code.substr(0, regex2.lastIndex - 12);
const codeBefore = code.substr(0, regex.lastIndex - match[0].length);
const linesBefore = codeBefore.split('\n');
const line = linesBefore[linesBefore.length - 1];

if (
regex3.test(line) ||
regex4.test(line)
(line.match(/['"]/g) || []).length % 2 === 1 ||
/^\s*(?:\/\/|\/\*|\*)/.test(line) ||
/\: |as |[\|\<'"]$/.test(line)
) {
continue;
}

const loc = {
line: linesBefore.length,
column: line.length
};

context.report({
node: node,
loc: loc,
loc: {
line: linesBefore.length,
column: line.length
},
message: message
});
}
Expand Down
64 changes: 64 additions & 0 deletions lib/rules/no-mixin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* @fileoverview Create and use events instead of mixins modifications.
*/
'use strict';

const message = 'Do not use mixins.';

//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------

module.exports = {
meta: {
docs: {
description: message,
category: 'Migration',
recommended: false
},
fixable: null, // or "code" or "whitespace"
schema: [
// fill in your schema
]
},

create: function (context) {

// variables should be defined here
const code = context.getSourceCode().lines.join('\n');

//----------------------------------------------------------------------
// Helpers
//----------------------------------------------------------------------
const program = (node) => {

const regex = /(?:import|from)\s+\'[^']*\/(Mixins\/)/g;

let match;

while (match = regex.exec(code)) {
const codeBefore = code.substr(0, regex.lastIndex - match[1].length);
const linesBefore = codeBefore.split('\n');
const line = linesBefore[linesBefore.length - 1];

context.report({
node: node,
loc: {
line: linesBefore.length,
column: line.length
},
message: message
});
}
};

//----------------------------------------------------------------------
// Public
//----------------------------------------------------------------------
return {

Program: program

};
}
};
5 changes: 3 additions & 2 deletions lib/rules/no-optional-chaining.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ module.exports = {
const program = (node) => {

const pattern = /\?\.[\w\[\(]/g;
const match = pattern.exec(code);

if (match) {
let match;

while (match = pattern.exec(code)) {
const codeBefore = code.substr(0, pattern.lastIndex - match[0].length);
const linesBefore = codeBefore.split('\n');
const line = linesBefore[linesBefore.length - 1];
Expand Down
64 changes: 64 additions & 0 deletions lib/rules/no-wrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* @fileoverview Create and use events instead of wrap modifications.
*/
'use strict';

const message = 'Do not use wrap.';

//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------

module.exports = {
meta: {
docs: {
description: message,
category: 'Migration',
recommended: false
},
fixable: null, // or "code" or "whitespace"
schema: [
// fill in your schema
]
},

create: function (context) {

// variables should be defined here
const code = context.getSourceCode().lines.join('\n');

//----------------------------------------------------------------------
// Helpers
//----------------------------------------------------------------------
const program = (node) => {

const regex = /(?:^|\s)(wrap\s*\()/g;

let match;

while (match = regex.exec(code)) {
const codeBefore = code.substr(0, regex.lastIndex - match[1].length);
const linesBefore = codeBefore.split('\n');
const line = linesBefore[linesBefore.length - 1];

context.report({
node: node,
loc: {
line: linesBefore.length,
column: line.length
},
message: message
});
}
};

//----------------------------------------------------------------------
// Public
//----------------------------------------------------------------------
return {

Program: program

};
}
};
Loading

0 comments on commit 7f3d924

Please sign in to comment.