0
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-02-06 04:08:22 +01:00

Change remaining JS files to comply with ESLint config.

This commit is contained in:
Bardi Harborow 2016-12-31 16:25:26 +11:00
parent a8100e1f01
commit 869dc64038
7 changed files with 104 additions and 101 deletions

View File

@ -7,26 +7,25 @@
*/ */
module.exports = function (grunt) { module.exports = function (grunt) {
'use strict'; 'use strict'
// Force use of Unix newlines // Force use of Unix newlines
grunt.util.linefeed = '\n'; grunt.util.linefeed = '\n'
RegExp.quote = function (string) { RegExp.quote = function (string) {
return string.replace(/[-\\^$*+?.()|[\]{}]/g, '\\$&'); return string.replace(/[-\\^$*+?.()|[\]{}]/g, '\\$&')
}; }
var fs = require('fs'); var path = require('path')
var path = require('path'); var isTravis = require('is-travis')
var isTravis = require('is-travis');
var configBridge = grunt.file.readJSON('./grunt/configBridge.json', { encoding: 'utf8' }); var configBridge = grunt.file.readJSON('./grunt/configBridge.json', { encoding: 'utf8' })
Object.keys(configBridge.paths).forEach(function (key) { Object.keys(configBridge.paths).forEach(function (key) {
configBridge.paths[key].forEach(function (val, i, arr) { configBridge.paths[key].forEach(function (val, i, arr) {
arr[i] = path.join('./docs', val); arr[i] = path.join('./docs', val)
}); })
}); })
// Project configuration. // Project configuration.
grunt.initConfig({ grunt.initConfig({
@ -100,7 +99,7 @@ module.exports = function (grunt) {
options: { options: {
// Custom function to remove all export and import statements // Custom function to remove all export and import statements
process: function (src) { process: function (src) {
return src.replace(/^(export|import).*/gm, ''); return src.replace(/^(export|import).*/gm, '')
} }
}, },
bootstrap: { bootstrap: {
@ -275,83 +274,83 @@ module.exports = function (grunt) {
} }
} }
}); })
// These plugins provide necessary tasks. // These plugins provide necessary tasks.
require('load-grunt-tasks')(grunt, { scope: 'devDependencies', require('load-grunt-tasks')(grunt, { scope: 'devDependencies',
// Exclude Sass compilers. We choose the one to load later on. // Exclude Sass compilers. We choose the one to load later on.
pattern: ['grunt-*', '!grunt-sass', '!grunt-contrib-sass'] }); pattern: ['grunt-*', '!grunt-sass', '!grunt-contrib-sass'] })
require('time-grunt')(grunt); require('time-grunt')(grunt)
// Docs HTML validation task // Docs HTML validation task
grunt.registerTask('validate-html', ['jekyll:docs', 'htmllint', 'exec:htmlhint']); grunt.registerTask('validate-html', ['jekyll:docs', 'htmllint', 'exec:htmlhint'])
var runSubset = function (subset) { var runSubset = function (subset) {
return !process.env.TWBS_TEST || process.env.TWBS_TEST === subset; return !process.env.TWBS_TEST || process.env.TWBS_TEST === subset
}; }
var isUndefOrNonZero = function (val) { var isUndefOrNonZero = function (val) {
return val === undefined || val !== '0'; return val === undefined || val !== '0'
}; }
// Test task. // Test task.
var testSubtasks = []; var testSubtasks = []
// Skip core tests if running a different subset of the test suite // Skip core tests if running a different subset of the test suite
if (runSubset('core') && if (runSubset('core') &&
// Skip core tests if this is a Savage build // Skip core tests if this is a Savage build
process.env.TRAVIS_REPO_SLUG !== 'twbs-savage/bootstrap') { process.env.TRAVIS_REPO_SLUG !== 'twbs-savage/bootstrap') {
testSubtasks = testSubtasks.concat(['dist-css', 'dist-js', 'test-scss', 'qunit', 'docs']); testSubtasks = testSubtasks.concat(['dist-css', 'dist-js', 'test-scss', 'qunit', 'docs'])
} }
// Skip HTML validation if running a different subset of the test suite // Skip HTML validation if running a different subset of the test suite
if (runSubset('validate-html') && if (runSubset('validate-html') &&
isTravis && isTravis &&
// Skip HTML5 validator when [skip validator] is in the commit message // Skip HTML5 validator when [skip validator] is in the commit message
isUndefOrNonZero(process.env.TWBS_DO_VALIDATOR)) { isUndefOrNonZero(process.env.TWBS_DO_VALIDATOR)) {
testSubtasks.push('validate-html'); testSubtasks.push('validate-html')
} }
// Only run Sauce Labs tests if there's a Sauce access key // Only run Sauce Labs tests if there's a Sauce access key
if (typeof process.env.SAUCE_ACCESS_KEY !== 'undefined' && if (typeof process.env.SAUCE_ACCESS_KEY !== 'undefined' &&
// Skip Sauce if running a different subset of the test suite // Skip Sauce if running a different subset of the test suite
runSubset('sauce-js-unit')) { runSubset('sauce-js-unit')) {
testSubtasks = testSubtasks.concat(['dist', 'docs-css', 'docs-js', 'clean:docs', 'copy:docs']); testSubtasks = testSubtasks.concat(['dist', 'docs-css', 'docs-js', 'clean:docs', 'copy:docs'])
// Skip Sauce on Travis when [skip sauce] is in the commit message // Skip Sauce on Travis when [skip sauce] is in the commit message
if (isUndefOrNonZero(process.env.TWBS_DO_SAUCE)) { if (isUndefOrNonZero(process.env.TWBS_DO_SAUCE)) {
testSubtasks.push('connect'); testSubtasks.push('connect')
testSubtasks.push('saucelabs-qunit'); testSubtasks.push('saucelabs-qunit')
} }
} }
grunt.registerTask('test', testSubtasks); grunt.registerTask('test', testSubtasks)
// JS distribution task. // JS distribution task.
grunt.registerTask('dist-js', ['babel:dev', 'concat', 'babel:dist', 'stamp', 'exec:uglify']); grunt.registerTask('dist-js', ['babel:dev', 'concat', 'babel:dist', 'stamp', 'exec:uglify'])
grunt.registerTask('test-scss', ['exec:scss-lint']); grunt.registerTask('test-scss', ['exec:scss-lint']);
// CSS distribution task. // CSS distribution task.
// Supported Compilers: sass (Ruby) and libsass. // Supported Compilers: sass (Ruby) and libsass.
(function (sassCompilerName) { (function (sassCompilerName) {
require('./grunt/bs-sass-compile/' + sassCompilerName + '.js')(grunt); require('./grunt/bs-sass-compile/' + sassCompilerName + '.js')(grunt)
})(process.env.TWBS_SASS || 'libsass'); }(process.env.TWBS_SASS || 'libsass'))
// grunt.registerTask('sass-compile', ['sass:core', 'sass:extras', 'sass:docs']); // grunt.registerTask('sass-compile', ['sass:core', 'sass:extras', 'sass:docs']);
grunt.registerTask('sass-compile', ['sass:core', 'sass:extras', 'sass:docs']); grunt.registerTask('sass-compile', ['sass:core', 'sass:extras', 'sass:docs'])
grunt.registerTask('dist-css', ['sass-compile', 'exec:postcss', 'exec:clean-css', 'exec:clean-css-docs']); grunt.registerTask('dist-css', ['sass-compile', 'exec:postcss', 'exec:clean-css', 'exec:clean-css-docs'])
// Full distribution task. // Full distribution task.
grunt.registerTask('dist', ['clean:dist', 'dist-css', 'dist-js']); grunt.registerTask('dist', ['clean:dist', 'dist-css', 'dist-js'])
// Default task. // Default task.
grunt.registerTask('default', ['clean:dist', 'test']); grunt.registerTask('default', ['clean:dist', 'test'])
// Docs task. // Docs task.
grunt.registerTask('docs-css', ['exec:clean-css-docs', 'exec:postcss-docs']); grunt.registerTask('docs-css', ['exec:clean-css-docs', 'exec:postcss-docs'])
grunt.registerTask('lint-docs-css', ['exec:scss-lint-docs']); grunt.registerTask('lint-docs-css', ['exec:scss-lint-docs'])
grunt.registerTask('docs-js', ['exec:uglify-docs']); grunt.registerTask('docs-js', ['exec:uglify-docs'])
grunt.registerTask('docs', ['lint-docs-css', 'docs-css', 'docs-js', 'clean:docs', 'copy:docs']); grunt.registerTask('docs', ['lint-docs-css', 'docs-css', 'docs-js', 'clean:docs', 'copy:docs'])
grunt.registerTask('docs-github', ['jekyll:github']); grunt.registerTask('docs-github', ['jekyll:github'])
grunt.registerTask('prep-release', ['dist', 'docs', 'docs-github', 'compress']); grunt.registerTask('prep-release', ['dist', 'docs', 'docs-github', 'compress'])
// Publish to GitHub // Publish to GitHub
grunt.registerTask('publish', ['buildcontrol:pages']); grunt.registerTask('publish', ['buildcontrol:pages'])
}; }

View File

@ -10,7 +10,7 @@
*/ */
// Intended to prevent false-positive bug reports about Bootstrap not working properly in old versions of IE due to folks testing using IE's unreliable emulation modes. // Intended to prevent false-positive bug reports about Bootstrap not working properly in old versions of IE due to folks testing using IE's unreliable emulation modes.
(function () { (function () {
'use strict'; 'use strict'
function emulatedIEMajorVersion() { function emulatedIEMajorVersion() {
var groups = /MSIE ([0-9.]+)/.exec(window.navigator.userAgent) var groups = /MSIE ([0-9.]+)/.exec(window.navigator.userAgent)
@ -49,4 +49,4 @@
if (emulated !== nonEmulated) { if (emulated !== nonEmulated) {
window.alert('WARNING: You appear to be using IE' + nonEmulated + ' in IE' + emulated + ' emulation mode.\nIE emulation modes can behave significantly differently from ACTUAL older versions of IE.\nPLEASE DON\'T FILE BOOTSTRAP BUGS based on testing in IE emulation modes!') window.alert('WARNING: You appear to be using IE' + nonEmulated + ' in IE' + emulated + ' emulation mode.\nIE emulation modes can behave significantly differently from ACTUAL older versions of IE.\nPLEASE DON\'T FILE BOOTSTRAP BUGS based on testing in IE emulation modes!')
} }
})(); }())

View File

@ -9,7 +9,7 @@
// https://getbootstrap.com/getting-started/#support-ie10-width // https://getbootstrap.com/getting-started/#support-ie10-width
(function () { (function () {
'use strict'; 'use strict'
if (navigator.userAgent.match(/IEMobile\/10\.0/)) { if (navigator.userAgent.match(/IEMobile\/10\.0/)) {
var msViewportStyle = document.createElement('style') var msViewportStyle = document.createElement('style')
@ -21,4 +21,4 @@
document.head.appendChild(msViewportStyle) document.head.appendChild(msViewportStyle)
} }
})(); }())

View File

@ -12,8 +12,8 @@
/* global Clipboard, anchors */ /* global Clipboard, anchors */
!function ($) { (function ($) {
'use strict'; 'use strict'
$(function () { $(function () {
@ -86,11 +86,11 @@
}) })
}(jQuery) }(jQuery))
;(function () { ;(function () {
'use strict'; 'use strict'
anchors.options.placement = 'left'; anchors.options.placement = 'left'
anchors.add('.bd-content > h1, .bd-content > h2, .bd-content > h3, .bd-content > h4, .bd-content > h5') anchors.add('.bd-content > h1, .bd-content > h2, .bd-content > h3, .bd-content > h4, .bd-content > h5')
})(); }())

View File

@ -28,6 +28,6 @@ module.exports = function configureLibsass(grunt) {
} }
} }
} }
}); })
grunt.loadNpmTasks('grunt-sass'); grunt.loadNpmTasks('grunt-sass')
}; }

View File

@ -9,7 +9,7 @@ module.exports = function configureRubySass(grunt) {
style: 'expanded', style: 'expanded',
trace: true, trace: true,
bundleExec: true bundleExec: true
}; }
grunt.config.merge({ grunt.config.merge({
sass: { sass: {
core: { core: {
@ -32,6 +32,6 @@ module.exports = function configureRubySass(grunt) {
} }
} }
} }
}); })
grunt.loadNpmTasks('grunt-contrib-sass'); grunt.loadNpmTasks('grunt-contrib-sass')
}; }

View File

@ -1,5 +1,6 @@
#!/usr/bin/env node #!/usr/bin/env node
'use strict';
'use strict'
/*! /*!
* Script to update version number references in the project. * Script to update version number references in the project.
@ -7,87 +8,90 @@
* Copyright 2015 Twitter, Inc. * Copyright 2015 Twitter, Inc.
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
*/ */
var fs = require('fs');
var path = require('path'); /* global Set */
var sh = require('shelljs');
sh.config.fatal = true; var fs = require('fs')
var sed = sh.sed; var path = require('path')
var sh = require('shelljs')
sh.config.fatal = true
var sed = sh.sed
// Blame TC39... https://github.com/benjamingr/RegExp.escape/issues/37 // Blame TC39... https://github.com/benjamingr/RegExp.escape/issues/37
RegExp.quote = function (string) { RegExp.quote = function (string) {
return string.replace(/[-\\^$*+?.()|[\]{}]/g, '\\$&'); return string.replace(/[-\\^$*+?.()|[\]{}]/g, '\\$&')
}; }
RegExp.quoteReplacement = function (string) { RegExp.quoteReplacement = function (string) {
return string.replace(/[$]/g, '$$'); return string.replace(/[$]/g, '$$')
}; }
var DRY_RUN = false; var DRY_RUN = false
function walkAsync(directory, excludedDirectories, fileCallback, errback) { function walkAsync(directory, excludedDirectories, fileCallback, errback) {
if (excludedDirectories.has(path.parse(directory).base)) { if (excludedDirectories.has(path.parse(directory).base)) {
return; return
} }
fs.readdir(directory, function (err, names) { fs.readdir(directory, function (err, names) {
if (err) { if (err) {
errback(err); errback(err)
return; return
} }
names.forEach(function (name) { names.forEach(function (name) {
var filepath = path.join(directory, name); var filepath = path.join(directory, name)
fs.lstat(filepath, function (err, stats) { fs.lstat(filepath, function (err, stats) {
if (err) { if (err) {
process.nextTick(errback, err); process.nextTick(errback, err)
return; return
} }
if (stats.isSymbolicLink()) { if (stats.isSymbolicLink()) {
return; return
} }
else if (stats.isDirectory()) { else if (stats.isDirectory()) {
process.nextTick(walkAsync, filepath, excludedDirectories, fileCallback, errback); process.nextTick(walkAsync, filepath, excludedDirectories, fileCallback, errback)
} }
else if (stats.isFile()) { else if (stats.isFile()) {
process.nextTick(fileCallback, filepath); process.nextTick(fileCallback, filepath)
} }
}); })
}); })
}); })
} }
function replaceRecursively(directory, excludedDirectories, allowedExtensions, original, replacement) { function replaceRecursively(directory, excludedDirectories, allowedExtensions, original, replacement) {
original = new RegExp(RegExp.quote(original), 'g'); original = new RegExp(RegExp.quote(original), 'g')
replacement = RegExp.quoteReplacement(replacement); replacement = RegExp.quoteReplacement(replacement)
var updateFile = !DRY_RUN ? function (filepath) { var updateFile = !DRY_RUN ? function (filepath) {
if (allowedExtensions.has(path.parse(filepath).ext)) { if (allowedExtensions.has(path.parse(filepath).ext)) {
sed('-i', original, replacement, filepath); sed('-i', original, replacement, filepath)
} }
} : function (filepath) { } : function (filepath) {
if (allowedExtensions.has(path.parse(filepath).ext)) { if (allowedExtensions.has(path.parse(filepath).ext)) {
console.log('FILE: ' + filepath); console.log('FILE: ' + filepath)
} }
else { else {
console.log('EXCLUDED:' + filepath); console.log('EXCLUDED:' + filepath)
} }
}; }
walkAsync(directory, excludedDirectories, updateFile, function (err) { walkAsync(directory, excludedDirectories, updateFile, function (err) {
console.error('ERROR while traversing directory!:'); console.error('ERROR while traversing directory!:')
console.error(err); console.error(err)
process.exit(1); process.exit(1)
}); })
} }
function main(args) { function main(args) {
if (args.length !== 2) { if (args.length !== 2) {
console.error('USAGE: change-version old_version new_version'); console.error('USAGE: change-version old_version new_version')
console.error('Got arguments:', args); console.error('Got arguments:', args)
process.exit(1); process.exit(1)
} }
var oldVersion = args[0]; var oldVersion = args[0]
var newVersion = args[1]; var newVersion = args[1]
var EXCLUDED_DIRS = new Set([ var EXCLUDED_DIRS = new Set([
'.git', '.git',
'node_modules', 'node_modules',
'vendor' 'vendor'
]); ])
var INCLUDED_EXTENSIONS = new Set([ var INCLUDED_EXTENSIONS = new Set([
// This extension whitelist is how we avoid modifying binary files // This extension whitelist is how we avoid modifying binary files
'', '',
@ -99,8 +103,8 @@ function main(args) {
'.scss', '.scss',
'.txt', '.txt',
'.yml' '.yml'
]); ])
replaceRecursively('.', EXCLUDED_DIRS, INCLUDED_EXTENSIONS, oldVersion, newVersion); replaceRecursively('.', EXCLUDED_DIRS, INCLUDED_EXTENSIONS, oldVersion, newVersion)
} }
main(process.argv.slice(2)); main(process.argv.slice(2))