diff --git a/src/bootlint.js b/src/bootlint.js index e51bdb60..0b8344a3 100644 --- a/src/bootlint.js +++ b/src/bootlint.js @@ -34,6 +34,7 @@ var LocationIndex = _location.LocationIndex; var NUM2SCREEN = ['xs', 'sm', 'md', 'lg']; var IN_NODE_JS = !!(cheerio.load); var MIN_JQUERY_VERSION = '1.9.1';// as of Bootstrap v3.3.0 + var CURRENT_BOOTSTRAP_VERSION = '3.3.1'; function compareNums(a, b) { return a - b; @@ -43,6 +44,13 @@ var LocationIndex = _location.LocationIndex; return node.type === 'directive' && node.name === '!doctype'; } + var tagNameOf = IN_NODE_JS ? function (element) { + return element.name.toUpperCase(); + } : function (element) { + /* @covignore */ + return element.tagName.toUpperCase(); + }; + function filenameFromUrl(url) { var filename = url.replace(/[#?].*$/, ''); // strip querystring & fragment ID var lastSlash = filename.lastIndexOf('/'); @@ -780,6 +788,82 @@ var LocationIndex = _location.LocationIndex; reporter('Using `.pull-left` or `.pull-right` as part of the media object component is deprecated as of Bootstrap v3.3.0. Use `.media-left` or `.media-right` instead.', mediaPulls); } }); + 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 PLUGINS = [ + 'affix', + 'alert', + 'button', + 'carousel', + 'collapse', + 'dropdown', + 'modal', + 'popover', + 'scrollspy', + 'tab', + 'tooltip' + ]; + var theWindow = null; + try { + /*eslint-disable no-undef, block-scoped-var */ + theWindow = window;// jshint ignore:line + /*eslint-enable no-undef, block-scoped-var */ + } + catch (e) { + // deliberately do nothing + } + var globaljQuery = theWindow && (theWindow.$ || theWindow.jQuery); + /* @covignore */ + if (globaljQuery) { + var versions = PLUGINS.map(function (pluginName) { + var plugin = globaljQuery.fn[pluginName]; + if (!plugin) { + return undefined; + } + var constructor = plugin.Constructor; + if (!constructor) { + return undefined; + } + return constructor.VERSION; + }).filter(function (version) { + return version !== undefined; + }).sort(semver.compare); + if (versions.length) { + var minVersion = versions[0]; + reporter(OUTDATED_BOOTSTRAP + minVersion); + return; + } + } + // check for Bootstrap s and + + + + + + + + + +
+ +