diff options
author | Herst <Herst@users.noreply.github.com> | 2018-09-09 13:36:57 +0300 |
---|---|---|
committer | Herst <Herst@users.noreply.github.com> | 2019-07-28 12:14:32 +0300 |
commit | c48b6f8dcede66013f879cead19bef49fbffdb16 (patch) | |
tree | b0834f4b86c87dba507f17afe772463a811ab2b6 | |
parent | 79ca1090de40780f85d06a51e471710ab0d0fb77 (diff) |
Remove JS-related checksnext-remove-js-stuff
Removed:
W005 (jQuery)
W013 (Bootstrap version)
W015 (Bootstrap 4 detection)
E007 (Only one copy of Bootstrap)
-rw-r--r-- | src/bootlint.js | 216 | ||||
-rw-r--r-- | test/bootlint_test.js | 58 |
2 files changed, 0 insertions, 274 deletions
diff --git a/src/bootlint.js b/src/bootlint.js index 2d984f1..ff96436 100644 --- a/src/bootlint.js +++ b/src/bootlint.js @@ -6,8 +6,6 @@ */ var cheerio = require('cheerio'); -var parseUrl = require('url').parse; -var semver = require('semver'); var voidElements = require('void-elements'); var _location = require('./location'); @@ -34,32 +32,6 @@ var LocationIndex = _location.LocationIndex; }; var NUM2SCREEN = ['', 'sm', 'md', 'lg', 'xl']; var IN_NODE_JS = Boolean(cheerio.load); - var MIN_JQUERY_VERSION = '1.9.1'; // as of Bootstrap v3.3.0 - var CURRENT_BOOTSTRAP_VERSION = '3.4.1'; - var BOOTSTRAP_VERSION_4 = '4.0.0'; - var PLUGINS = [ - 'affix', - 'alert', - 'button', - 'carousel', - 'collapse', - 'dropdown', - 'modal', - 'popover', - 'scrollspy', - 'tab', - 'tooltip' - ]; - var BOOTSTRAP_FILES = [ - 'link[rel="stylesheet"][href$="/bootstrap.css"]', - 'link[rel="stylesheet"][href="bootstrap.css"]', - 'link[rel="stylesheet"][href$="/bootstrap.min.css"]', - 'link[rel="stylesheet"][href="bootstrap.min.css"]', - 'script[src$="/bootstrap.js"]', - 'script[src="bootstrap.js"]', - 'script[src$="/bootstrap.min.js"]', - 'script[src="bootstrap.min.js"]' - ].join(','); var WIKI_URL = 'https://github.com/twbs/bootlint/wiki/'; function compareNums(a, b) { @@ -189,79 +161,6 @@ var LocationIndex = _location.LocationIndex; } /** - * @returns {(Window|null)} The browser window object, or null if this is not running in a browser environment - */ - function getBrowserWindowObject() { - var theWindow = null; - try { - /* eslint-disable no-undef, block-scoped-var */ - theWindow = window; - /* eslint-enable no-undef, block-scoped-var */ - } catch (e) { - // deliberately do nothing - // empty - } - - return theWindow; - } - - function versionsIn(strings) { - return strings.map(function (str) { - var match = str.match(/^\d+\.\d+\.\d+$/); - return match ? match[0] : null; - }).filter(function (match) { - return match !== null; - }); - } - - function versionInLinkedElement($, element) { - var elem = $(element); - var urlAttr = tagNameOf(element) === 'LINK' ? 'href' : 'src'; - var pathSegments = parseUrl(elem.attr(urlAttr)).pathname.split('/'); - var versions = versionsIn(pathSegments); - if (!versions.length) { - return null; - } - var version = versions[versions.length - 1]; - return version; - } - - function jqueryPluginVersions(jQuery) { - /* istanbul ignore next */ - return PLUGINS.map(function (pluginName) { - var plugin = jQuery.fn[pluginName]; - if (!plugin) { - return undefined; - } - var constructor = plugin.Constructor; - if (!constructor) { - return undefined; - } - return constructor.VERSION; - }).filter(function (version) { - return typeof version !== 'undefined'; - }).sort(semver.compare); - } - - function bootstrapScriptsIn($) { - var longhands = $('script[src*="bootstrap.js"]').filter(function (i, script) { - var url = $(script).attr('src'); - var filename = filenameFromUrl(url); - return filename === 'bootstrap.js'; - }); - var minifieds = $('script[src*="bootstrap.min.js"]').filter(function (i, script) { - var url = $(script).attr('src'); - var filename = filenameFromUrl(url); - return filename === 'bootstrap.min.js'; - }); - - return { - longhands: longhands, - minifieds: minifieds - }; - } - - /** * @param {integer} id Unique string ID for this type of lint error. Of the form "E###" (e.g. "E123"). * @param {string} message Human-readable string describing the error * @param {jQuery} elements jQuery or Cheerio collection of referenced DOM elements pointing to all problem locations in the document @@ -346,84 +245,6 @@ var LocationIndex = _location.LocationIndex; }); */ /* - addLinter('W005', function lintJquery($, reporter) { - var OLD_JQUERY = 'Found what might be an outdated version of jQuery; Bootstrap requires jQuery v' + MIN_JQUERY_VERSION + ' or higher'; - var NO_JQUERY_BUT_BS_JS = 'Unable to locate jQuery, which is required for Bootstrap\'s JavaScript plugins to work'; - var NO_JQUERY_NOR_BS_JS = 'Unable to locate jQuery, which is required for Bootstrap\'s JavaScript plugins to work; however, you might not be using Bootstrap\'s JavaScript'; - var bsScripts = bootstrapScriptsIn($); - var hasBsJs = Boolean(bsScripts.minifieds.length || bsScripts.longhands.length); - var theWindow = null; - try { - // eslint-disable no-undef, block-scoped-var - theWindow = window; - // eslint-enable no-undef, block-scoped-var - } catch (e) { - // deliberately do nothing - // empty - } - // istanbul ignore if - if (theWindow) { - // check browser global jQuery - var globaljQuery = theWindow.$ || theWindow.jQuery; - if (globaljQuery) { - var globalVersion = null; - try { - globalVersion = globaljQuery.fn.jquery.split(' ')[0]; - } catch (e) { - // skip; not actually jQuery? - // empty - } - if (globalVersion) { - // pad out short version numbers (e.g. '1.7') - while (globalVersion.match(/\./g).length < 2) { - globalVersion += '.0'; - } - - var upToDate = null; - try { - upToDate = semver.gte(globalVersion, MIN_JQUERY_VERSION, true); - } catch (e) { - // invalid version number - // empty - } - if (upToDate === false) { - reporter(OLD_JQUERY); - } - if (upToDate !== null) { - return; - } - } - } - } - - // check for jQuery <script>s - var jqueries = $([ - 'script[src*="jquery"]', - 'script[src*="jQuery"]' - ].join(',')); - if (!jqueries.length) { - reporter(hasBsJs ? NO_JQUERY_BUT_BS_JS : NO_JQUERY_NOR_BS_JS); - return; - } - jqueries.each(function () { - var script = $(this); - var pathSegments = parseUrl(script.attr('src')).pathname.split('/'); - var filename = pathSegments[pathSegments.length - 1]; - if (!/^j[qQ]uery(\.min)?\.js$/.test(filename)) { - return; - } - var versions = versionsIn(pathSegments); - if (!versions.length) { - return; - } - var version = versions[versions.length - 1]; - if (!semver.gte(version, MIN_JQUERY_VERSION, true)) { - reporter(OLD_JQUERY, script); - } - }); - }); - */ - /* addLinter('W006', function lintTooltipsOnDisabledElems($, reporter) { var selector = [ '[disabled][data-toggle="tooltip"]', @@ -494,35 +315,6 @@ var LocationIndex = _location.LocationIndex; }); */ /* - addLinter('W013', function lintOutdatedBootstrap($, reporter) { - var OUTDATED_BOOTSTRAP = 'Bootstrap version might be outdated. Latest version is at least ' + CURRENT_BOOTSTRAP_VERSION + ' ; saw what appears to be usage of Bootstrap '; - var theWindow = getBrowserWindowObject(); - var globaljQuery = theWindow && (theWindow.$ || theWindow.jQuery); - // istanbul ignore if - if (globaljQuery) { - var versions = jqueryPluginVersions(globaljQuery); - if (versions.length) { - var minVersion = versions[0]; - if (semver.lt(minVersion, CURRENT_BOOTSTRAP_VERSION, true)) { - reporter(OUTDATED_BOOTSTRAP + minVersion); - return; - } - } - } - // check for Bootstrap <link>s and <script>s - var bootstraps = $(BOOTSTRAP_FILES); - bootstraps.each(function () { - var version = versionInLinkedElement($, this); - if (version === null) { - return; - } - if (semver.lt(version, CURRENT_BOOTSTRAP_VERSION, true)) { - reporter(OUTDATED_BOOTSTRAP + version, $(this)); - } - }); - }); - */ - /* addLinter('W014', function lintCarouselControls($, reporter) { var controls = $('.carousel-indicators > li, .carousel-control'); controls.each(function (_index, cont) { @@ -629,14 +421,6 @@ var LocationIndex = _location.LocationIndex; }); */ /* - addLinter('E007', function lintBootstrapJs($, reporter) { - var scripts = bootstrapScriptsIn($); - if (scripts.longhands.length && scripts.minifieds.length) { - reporter('Only one copy of Bootstrap\'s JS should be included; currently the webpage includes both bootstrap.js and bootstrap.min.js', scripts.longhands.add(scripts.minifieds)); - } - }); - */ - /* addLinter('E009', function lintMissingInputGroupSizes($, reporter) { var selector = [ '.input-group:not(.input-group-lg) .btn-lg', diff --git a/test/bootlint_test.js b/test/bootlint_test.js index bbca813..c01e7bb 100644 --- a/test/bootlint_test.js +++ b/test/bootlint_test.js @@ -130,45 +130,6 @@ exports.bootlint = { test.done(); }, /* - 'jQuery': function (test) { - test.expect(5); - test.deepEqual(lintHtml(utf8Fixture('jquery/present.html')), - [], - 'should not complain when jQuery is present.'); - test.deepEqual(lintHtml(utf8Fixture('jquery/jquery-plugin.html')), - [], - 'should not complain when jQuery & a plugin is present.'); - test.deepEqual(lintHtml(utf8Fixture('jquery/old-url.html')), - ['Found what might be an outdated version of jQuery; Bootstrap requires jQuery v1.9.1 or higher'], - 'should complain about old version of jQuery based on URL'); - test.deepEqual(lintHtml(utf8Fixture('jquery/missing.html')), - ['Unable to locate jQuery, which is required for Bootstrap\'s JavaScript plugins to work'], - 'should complain when jQuery appears to be missing.'); - test.deepEqual(lintHtml(utf8Fixture('jquery/and_bs_js_both_missing.html')), - ['Unable to locate jQuery, which is required for Bootstrap\'s JavaScript plugins to work; however, you might not be using Bootstrap\'s JavaScript'], - 'should complain differently when jQuery appears to be missing but Bootstrap\'s JS is also missing.'); - test.done(); - }, - */ - /* - 'bootstrap[.min].js': function (test) { - test.expect(4); - test.deepEqual(lintHtml(utf8Fixture('js/both.html')), - ['Only one copy of Bootstrap\'s JS should be included; currently the webpage includes both bootstrap.js and bootstrap.min.js'], - 'should complain when both bootstrap.js and bootstrap.min.js are included.'); - test.deepEqual(lintHtml(utf8Fixture('js/one.html')), - [], - 'should not complain when only 1 of bootstrap.js and bootstrap.min.js is included.'); - test.deepEqual(lintHtml(utf8Fixture('js/similar.html')), - [], - 'should not complain when only 1 of bootstrap.js and bootstrap.min.js is included but another JS file with "bootstrap" in its name is included.'); - test.deepEqual(lintHtml(utf8Fixture('js/weird.html')), - ['Only one copy of Bootstrap\'s JS should be included; currently the webpage includes both bootstrap.js and bootstrap.min.js'], - 'should complain when both bootstrap.js and bootstrap.min.js are included, even when their URLs use fragments and query strings.'); - test.done(); - }, - */ - /* 'input groups with impermissible kind of form control': function (test) { test.expect(3); test.deepEqual(lintHtml(utf8Fixture('input-group/textarea.html')), @@ -635,25 +596,6 @@ exports.bootlint = { test.done(); }, /* - 'outdated version of Bootstrap': function (test) { - test.expect(5); - test.deepEqual(lintHtml(utf8Fixture('outdated/bootstrap-css.html')), - ['Bootstrap version might be outdated. Latest version is at least 3.4.1 ; saw what appears to be usage of Bootstrap 3.2.0'], - 'should complain about outdated bootstrap.css.'); - test.deepEqual(lintHtml(utf8Fixture('outdated/bootstrap-min-css.html')), - ['Bootstrap version might be outdated. Latest version is at least 3.4.1 ; saw what appears to be usage of Bootstrap 3.2.0'], - 'should complain about outdated bootstrap.min.css.'); - test.deepEqual(lintHtml(utf8Fixture('outdated/bootstrap-js.html')), - ['Bootstrap version might be outdated. Latest version is at least 3.4.1 ; saw what appears to be usage of Bootstrap 3.2.0'], - 'should complain about outdated bootstrap.js.'); - test.deepEqual(lintHtml(utf8Fixture('outdated/bootstrap-min-js.html')), - ['Bootstrap version might be outdated. Latest version is at least 3.4.1 ; saw what appears to be usage of Bootstrap 3.2.0'], - 'should complain about outdated bootstrap.min.js.'); - test.deepEqual(lintHtml(utf8Fixture('outdated/bootstrap-extensions-okay.html')), - [], - 'should not complain about outdated libraries that just have "bootstrap" in their name.'); - test.done(); - }, */ /* 'carousel control target': function (test) { |