Skip to content

Commit

Permalink
Merge pull request #100 from wikimedia/lint
Browse files Browse the repository at this point in the history
Add linting
  • Loading branch information
jdforrester authored Aug 21, 2024
2 parents f85f073 + 92548d1 commit 0febe84
Show file tree
Hide file tree
Showing 14 changed files with 9,416 additions and 5,404 deletions.
17 changes: 17 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"root": true,
"extends": [
"wikimedia/server"
],
"rules": {
"camelcase": "off",
"no-console": "off",
"no-process-exit": "off",
"no-shadow": "off",
"no-underscore-dangle": "off",
"no-use-before-define": "off",
"es-x/no-hashbang": "off",
"n/no-process-exit": "off",
"jsdoc/newline-after-description": "off"
}
}
2 changes: 1 addition & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

strategy:
matrix:
node-version: [14.x, 16.x, 18.x]
node-version: [16.x, 18.x, 20.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
Expand Down
95 changes: 47 additions & 48 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
/*
Import modules
*/
var BBPromise = require('bluebird');
var cheerio = require('cheerio');
var preq = require('preq'); // Promisified Request library
var fs = BBPromise.promisifyAll(require('fs'));
const BBPromise = require( 'bluebird' );
const cheerio = require( 'cheerio' );
const preq = require( 'preq' ); // Promisified Request library
const fs = BBPromise.promisifyAll( require( 'fs' ) );

var index = require('./lib/index.js');
const index = require( './lib/index.js' );

/**
* Default exported function that takes a url string or
Expand All @@ -26,46 +26,44 @@ var index = require('./lib/index.js');
* @param {Function} [callback] Optional callback
* @return {Object} BBPromise for metadata
*/
exports = module.exports = function(urlOrOpts, callback) {
return preq.get(urlOrOpts
).then(function(response) {
return index.parseAll(cheerio.load(response.body));
}).nodeify(callback);
exports = module.exports = function ( urlOrOpts, callback ) {
return preq.get( urlOrOpts
).then( ( response ) => index.parseAll( cheerio.load( response.body ) ) ).nodeify( callback );
};

/**
* Exported function that takes html file and
* returns a BBPromise for all available metadata
*
* @param {String} path path Path to HTML file
* @param {Object} [opts] opts Additional options such as encoding
* @param {string} path path Path to HTML file
* @param {Object} [opts] opts Additional options such as encoding
* @param {Function} [callback] Optional callback
* @return {Object} BBPromise for metadata
*/
exports.loadFromFile = function(path, opts, callback) {
var defaultEncoding = 'utf-8';
exports.loadFromFile = function ( path, opts, callback ) {
const defaultEncoding = 'utf-8';

opts = opts || defaultEncoding;
if (typeof opts === 'function') {
if ( typeof opts === 'function' ) {
callback = opts;
opts = defaultEncoding;
}

return fs.readFileAsync(path, opts).then(html =>
index.parseAll(cheerio.load(html)).nodeify(callback)
return fs.readFileAsync( path, opts ).then(
( html ) => index.parseAll( cheerio.load( html ) ).nodeify( callback )
);
};

/**
* Exported function that takes html string and
* returns a BBPromise for all available metadata
*
* @param {String} html html String HTML of the page
* @param {string} html html String HTML of the page
* @param {Function} [callback] Optional callback
* @return {Object} BBPromise for metadata
*/
exports.loadFromString = function(html, callback) {
return index.parseAll(cheerio.load(html)).nodeify(callback);
exports.loadFromString = function ( html, callback ) {
return index.parseAll( cheerio.load( html ) ).nodeify( callback );
};

/**
Expand All @@ -76,8 +74,8 @@ exports.loadFromString = function(html, callback) {
* @param {Function} [callback] optional callback function
* @return {Object} BBPromise for metadata
*/
exports.parseAll = function(chtml, callback){
return index.parseAll(chtml).nodeify(callback);
exports.parseAll = function ( chtml, callback ) {
return index.parseAll( chtml ).nodeify( callback );
};

/**
Expand All @@ -87,8 +85,8 @@ exports.parseAll = function(chtml, callback){
* @param {Function} [callback] optional callback function
* @return {Object} BBPromise for metadata
*/
exports.parseBEPress = function(chtml, callback){
return index.parseBEPress(chtml).nodeify(callback);
exports.parseBEPress = function ( chtml, callback ) {
return index.parseBEPress( chtml ).nodeify( callback );
};

/**
Expand All @@ -98,19 +96,19 @@ exports.parseBEPress = function(chtml, callback){
* @param {Function} [callback] optional callback function
* @return {Object} BBPromise for metadata
*/
exports.parseCOinS = function(chtml, callback){
return index.parseCOinS(chtml).nodeify(callback);
exports.parseCOinS = function ( chtml, callback ) {
return index.parseCOinS( chtml ).nodeify( callback );
};

/**
* Parses value of COinS title tag
*
* @param {String} title String corresponding to value of title tag in span element
* @param {string} title String corresponding to value of title tag in span element
* @param {Function} [callback] Optional callback function
* @return {Object} BBPromise for metadata
*/
exports.parseCOinSTitle = function(title, callback){
return index.parseCOinSTitle(title).nodeify(callback);
exports.parseCOinSTitle = function ( title, callback ) {
return index.parseCOinSTitle( title ).nodeify( callback );
};

/**
Expand All @@ -120,8 +118,8 @@ exports.parseCOinSTitle = function(title, callback){
* @param {Function} [callback] optional callback function
* @return {Object} BBPromise for metadata
*/
exports.parseDublinCore = function(chtml, callback){
return index.parseDublinCore(chtml).nodeify(callback);
exports.parseDublinCore = function ( chtml, callback ) {
return index.parseDublinCore( chtml ).nodeify( callback );
};

/**
Expand All @@ -131,8 +129,8 @@ exports.parseDublinCore = function(chtml, callback){
* @param {Function} [callback] optional callback function
* @return {Object} BBPromise for metadata
*/
exports.parseEprints = function(chtml, callback){
return index.parseEprints(chtml).nodeify(callback);
exports.parseEprints = function ( chtml, callback ) {
return index.parseEprints( chtml ).nodeify( callback );
};

/**
Expand All @@ -142,8 +140,8 @@ exports.parseEprints = function(chtml, callback){
* @param {Function} [callback] optional callback function
* @return {Object} BBPromise for metadata
*/
exports.parseGeneral = function(chtml, callback){
return index.parseGeneral(chtml).nodeify(callback);
exports.parseGeneral = function ( chtml, callback ) {
return index.parseGeneral( chtml ).nodeify( callback );
};

/**
Expand All @@ -153,8 +151,8 @@ exports.parseGeneral = function(chtml, callback){
* @param {Function} [callback] optional callback function
* @return {Object} BBPromise for metadata
*/
exports.parseHighwirePress = function(chtml, callback){
return index.parseHighwirePress(chtml).nodeify(callback);
exports.parseHighwirePress = function ( chtml, callback ) {
return index.parseHighwirePress( chtml ).nodeify( callback );
};

/**
Expand All @@ -164,8 +162,8 @@ exports.parseHighwirePress = function(chtml, callback){
* @param {Function} [callback] optional callback function
* @return {Object} BBPromise for JSON-LD
*/
exports.parseJsonLd = function(chtml, callback){
return index.parseJsonLd(chtml).nodeify(callback);
exports.parseJsonLd = function ( chtml, callback ) {
return index.parseJsonLd( chtml ).nodeify( callback );
};

/**
Expand All @@ -175,8 +173,8 @@ exports.parseJsonLd = function(chtml, callback){
* @param {Function} [callback] optional callback function
* @return {Object} BBPromise for metadata
*/
exports.parseOpenGraph = function(chtml, callback){
return index.parseOpenGraph(chtml).nodeify(callback);
exports.parseOpenGraph = function ( chtml, callback ) {
return index.parseOpenGraph( chtml ).nodeify( callback );
};

/**
Expand All @@ -186,8 +184,8 @@ exports.parseOpenGraph = function(chtml, callback){
* @param {Function} [callback] optional callback function
* @return {Object} BBPromise for metadata
*/
exports.parseSchemaOrgMicrodata = function(chtml, callback){
return index.parseSchemaOrgMicrodata(chtml).nodeify(callback);
exports.parseSchemaOrgMicrodata = function ( chtml, callback ) {
return index.parseSchemaOrgMicrodata( chtml ).nodeify( callback );
};

/**
Expand All @@ -197,8 +195,8 @@ exports.parseSchemaOrgMicrodata = function(chtml, callback){
* @param {Function} [callback] optional callback function
* @return {Object} BBPromise for metadata
*/
exports.parseTwitter = function(chtml, callback){
return index.parseTwitter(chtml).nodeify(callback);
exports.parseTwitter = function ( chtml, callback ) {
return index.parseTwitter( chtml ).nodeify( callback );
};

/**
Expand All @@ -208,12 +206,13 @@ exports.parseTwitter = function(chtml, callback){
* @param {Function} [callback] optional callback function
* @return {Object} BBPromise for metadata
*/
exports.parsePrism = function(chtml, callback){
return index.parsePrism(chtml).nodeify(callback);
exports.parsePrism = function ( chtml, callback ) {
return index.parsePrism( chtml ).nodeify( callback );
};

/**
* Global exportable list of scraping promises with string keys
*
* @type {Object}
*/
exports.metadataFunctions = index.metadataFunctions;
Expand All @@ -222,4 +221,4 @@ exports.metadataFunctions = index.metadataFunctions;
Export the version
*/

exports.version = require('./package').version;
exports.version = require( './package' ).version;
Loading

0 comments on commit 0febe84

Please sign in to comment.