Skip to content

Build: Update dependencies #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"root": true,

"extends": "jquery",

"reportUnusedDisableDirectives": true,

"parserOptions": {
"ecmaVersion": 2018
},

"env": {
"es6": true,
"node": true
},

"rules": {
"strict": ["error", "global"]
}
}
17 changes: 0 additions & 17 deletions .jshintrc

This file was deleted.

1 change: 0 additions & 1 deletion .npmrc

This file was deleted.

16 changes: 9 additions & 7 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
module.exports = function( grunt ) {
"use strict";

grunt.loadNpmTasks( "grunt-contrib-jshint" );
module.exports = function( grunt ) {

grunt.initConfig({
grunt.initConfig( {
watch: {
files: "<config:lint.files>",
tasks: "default"
},
jshint: {
eslint: {
options: {
jshintrc: true
},
files: [ "Gruntfile.js", "tasks/**/*.js" ]
files: [ "*.js", "lib/**/*.js", "tasks/**/*.js" ]
}
});
} );

grunt.loadNpmTasks( "grunt-eslint" );

grunt.registerTask( "default", "jshint" );
grunt.registerTask( "default", "eslint" );

};
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
var syntaxHighlight = require( "./lib/highlight" );
"use strict";

const syntaxHighlight = require( "./lib/highlight" );

exports.syntaxHighlight = syntaxHighlight;

exports.postPreprocessors = {
_default: function( post, fileName, callback ) {
_default( post, _fileName, callback ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you add this underscore on purpose?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, our ESLint config requires all variables & function parameters to be used inside of the function body. For parameters it's not possible in 100% of cases and then prefixing with an underscore is an opt-out.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably use after-used

Copy link
Member Author

@mgol mgol May 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We had a discussion about that some time ago and we decided to use all as there are more cases where we'd leave internal unused parameters than in APIs where they have to be there. This applies especially to AMD module definitions where we've been constantly missing unused dependencies.

We had to prefix some parameters with _ in Core because of this rule but there weren't too many of them.

callback( null, post );
}
};
56 changes: 29 additions & 27 deletions lib/highlight.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
var fs = require( "fs" ),
hljs = require( "highlight.js" ),
cheerio = require( "cheerio" ),
he = require( "he" ),
grunt = require( "grunt" ),
lineNumberTemplate = fs.readFileSync( __dirname + "/lineNumberTemplate.jst", "utf-8" );
"use strict";

const fs = require( "fs" );
const hljs = require( "highlight.js" );
const cheerio = require( "cheerio" );
const he = require( "he" );
const grunt = require( "grunt" );
const lineNumberTemplate = fs.readFileSync( __dirname + "/lineNumberTemplate.jst", "utf-8" );

// When parsing the class attribute, make sure a class matches an actually
// highlightable language, instead of being presentational (e.g. 'example')
function getLanguageFromClass( str ) {
var classes = (str || "").split( " " ),
var classes = ( str || "" ).split( " " ),
i = 0,
length = classes.length;

for ( ; i < length; i++ ) {
if ( hljs.LANGUAGES[ classes[ i ].replace( /^lang-/, "" ) ] ) {
return classes[i].replace( /^lang-/, "" );
if ( hljs.getLanguage( classes[ i ].replace( /^lang-/, "" ) ) ) {
return classes[ i ].replace( /^lang-/, "" );
}
}

Expand All @@ -27,34 +29,34 @@ function outdent( string ) {
minTabs = Infinity,
rLeadingTabs = /^\t+/;

string.split( "\n" ).forEach(function( line, i, arr ) {
string.split( "\n" ).forEach( function( line, i, arr ) {

// Don't include first or last line if it's nothing but whitespace
if ( (i === 0 || i === arr.length - 1) && !line.trim().length ) {
if ( ( i === 0 || i === arr.length - 1 ) && !line.trim().length ) {
return;
}

// For empty lines inside the snippet, push a space so the line renders properly
if ( !line.trim().length ) {
adjustedLines.push(" ");
adjustedLines.push( " " );
return;
}

// Count how many leading tabs there are and update the global minimum
var match = line.match( rLeadingTabs ),
tabs = match ? match[0].length : 0;
tabs = match ? match[ 0 ].length : 0;
minTabs = Math.min( minTabs, tabs );

adjustedLines.push( line );
});
} );

if ( minTabs !== Infinity ) {

// Outdent the lines as much as possible
rOutdent = new RegExp( "^\t{" + minTabs + "}" );
adjustedLines = adjustedLines.map(function( line ) {
adjustedLines = adjustedLines.map( function( line ) {
return line.replace( rOutdent, "" );
});
} );
}

return adjustedLines.join( "\n" );
Expand All @@ -63,25 +65,25 @@ function outdent( string ) {
function syntaxHighlight( html ) {
var $ = cheerio.load( html );

$( "pre > code" ).each(function() {
$( "pre > code" ).each( function() {
var $t = $( this ),
code = he.decode( outdent( $t.html() ) ),
lang = $t.attr( "data-lang" ) ||
getLanguageFromClass( $t.attr( "class" ) ) ||
(code.trim().charAt( 0 ) === "<" ? "xml" : "") ||
( code.trim().charAt( 0 ) === "<" ? "xml" : "" ) ||
"javascript",
linenumAttr = $t.attr( "data-linenum" ),
linenum = parseInt( linenumAttr, 10 ) || 1,
gutter = linenumAttr === "false" ? false : true,
highlighted = hljs.highlight( lang, code ),
fixed = hljs.fixMarkup( highlighted.value, " " );
gutter = linenumAttr !== "false",
highlighted = hljs.highlight( code, { language: lang } ),
fixed = highlighted.value.replace( /\t/g, " " );

// Handle multi-line comments (#32)
fixed = fixed.replace(
/<span class="comment">\/\*([^<]+)\*\/<\/span>/g,
function( full, comment ) {
return "<span class=\"comment\">/*" +
comment.split( "\n" ).join( "</span>\n<span class=\"comment\">" ) +
/<span class="hljs-comment">\/\*([^<]+)\*\/<\/span>/g,
function( _full, comment ) {
return "<span class=\"hljs-comment\">/*" +
comment.split( "\n" ).join( "</span>\n<span class=\"hljs-comment\">" ) +
"*/</span>";
}
);
Expand All @@ -93,8 +95,8 @@ function syntaxHighlight( html ) {
gutter: gutter,
lang: lang
}
}));
});
} ) );
} );

return $.html();
}
Expand Down
20 changes: 10 additions & 10 deletions lib/util.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
var fs = require( "fs" ),
async = require( "async" ),
marked = require( "marked" );
"use strict";

const fs = require( "fs" );
const async = require( "async" );
const marked = require( "marked" );

function htmlEscape( text ) {
return text

// Supports keeping markup in source file, but drop from inline sample
.replace(
/<!-- @placeholder-start\((.+)\) -->[\s\S]+@placeholder-end -->/g,
function( match, input ) {
return "<!-- " + input + " -->";
}
( _match, input ) => "<!-- " + input + " -->"
)
.replace( /&/g, "&amp;" )
.replace( /</g, "&lt;" )
Expand All @@ -28,7 +28,7 @@ function parseMarkdown( src, options ) {
return marked.parser( tokens );
}

tokens.forEach(function( item ) {
tokens.forEach( function( item ) {
if ( item.type !== "heading" ) {
return;
}
Expand All @@ -53,10 +53,10 @@ function parseMarkdown( src, options ) {
"</a> " + parsedText + "</h" + item.depth + ">";

if ( options.generateToc ) {
toc += new Array( (item.depth - 1) * 2 + 1 ).join( " " ) + "* " +
toc += new Array( ( item.depth - 1 ) * 2 + 1 ).join( " " ) + "* " +
"[" + item.tocText + "](#" + item.tocId + ")\n";
}
});
} );

if ( options.generateToc ) {
tokens = marked.lexer( toc ).concat( tokens );
Expand Down Expand Up @@ -85,7 +85,7 @@ function eachFile( files, stepFn, complete ) {
}

complete( null, count );
});
} );
}

exports.htmlEscape = htmlEscape;
Expand Down
Loading