Merge pull request #2937 from overleaf/as-remove-global-lodash

Replace global Lodash with explicit imports in frontend

GitOrigin-RevId: b092647039975ac594b69ce1fa145fd03552cc60
This commit is contained in:
Alasdair Smith 2020-06-23 09:45:38 +01:00 committed by Copybot
parent 5636386c54
commit 0d2a768e1e
42 changed files with 87 additions and 42 deletions

View file

@ -22,7 +22,6 @@ import './modules/recursionHelper'
import './modules/errorCatcher'
import './modules/localStorage'
import './modules/sessionStorage'
import './utils/underscore'
// Configure dynamically loaded assets (via webpack) to be downloaded from CDN
// See: https://webpack.js.org/guides/public-path/#on-the-fly
// eslint-disable-next-line no-undef
@ -34,7 +33,6 @@ const App = angular
'autocomplete',
'RecursionHelper',
'ng-context-menu',
'underscore',
'ngSanitize',
'ipCookie',
'ErrorCatcher',

View file

@ -1,5 +1,6 @@
import _ from 'lodash'
import App from '../base'
App.directive('bookmarkableTabset', ($location, _) => ({
App.directive('bookmarkableTabset', $location => ({
restrict: 'A',
require: 'tabset',
link(scope, el, attrs, tabset) {

View file

@ -1,3 +1,4 @@
import _ from 'lodash'
/* global PassField */
/* eslint-disable

View file

@ -1,3 +1,4 @@
import _ from 'lodash'
/* eslint-disable
camelcase,
max-len,

View file

@ -1,3 +1,4 @@
import _ from 'lodash'
/* global MathJax */
import App from '../base'

View file

@ -1,3 +1,4 @@
import _ from 'lodash'
/* eslint-disable
camelcase,
handle-callback-err,

View file

@ -1,3 +1,4 @@
import _ from 'lodash'
/* eslint-disable
camelcase,
handle-callback-err,

View file

@ -1,3 +1,4 @@
import _ from 'lodash'
/* eslint-disable
camelcase,
max-len

View file

@ -1,3 +1,4 @@
import _ from 'lodash'
import CommandManager from './CommandManager'
import EnvironmentManager from './EnvironmentManager'
import PackageManager from './PackageManager'

View file

@ -1,3 +1,4 @@
import _ from 'lodash'
/* eslint-disable
max-len,
no-return-assign,

View file

@ -1,3 +1,4 @@
import _ from 'lodash'
/* eslint-disable
max-len,
*/

View file

@ -15,7 +15,7 @@
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
import _ from 'ace/ace'
import 'ace/ace'
import ColorManager from '../../../../colors/ColorManager'
let HighlightsManager
const { Range } = ace.require('ace/range')

View file

@ -1,3 +1,4 @@
import _ from 'lodash'
/* eslint-disable
max-len,
no-cond-assign,

View file

@ -1,3 +1,4 @@
import _ from 'lodash'
/* eslint-disable
max-len,
no-return-assign,

View file

@ -1,3 +1,4 @@
import _ from 'lodash'
/* eslint-disable
camelcase,
handle-callback-err,

View file

@ -1,3 +1,4 @@
import _ from 'lodash'
import App from '../../../base'
export default App.factory('files', function(ide) {

View file

@ -1,3 +1,4 @@
import _ from 'lodash'
/* eslint-disable
max-len,
*/

View file

@ -1,3 +1,4 @@
import _ from 'lodash'
/* eslint-disable
camelcase,
max-len,

View file

@ -10,7 +10,7 @@
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
import App from '../../../base'
const historyEntriesListController = function($scope, $element, $attrs, _) {
const historyEntriesListController = function($scope, $element, $attrs) {
const ctrl = this
ctrl.$entryListViewportEl = null
ctrl.isDragging = false

View file

@ -1,3 +1,4 @@
import _ from 'lodash'
/* eslint-disable
max-len,
*/
@ -12,7 +13,7 @@
import App from '../../../base'
import ColorManager from '../../colors/ColorManager'
import displayNameForUser from '../util/displayNameForUser'
const historyEntryController = function($scope, $element, $attrs, _) {
const historyEntryController = function($scope, $element, $attrs) {
const ctrl = this
// This method (and maybe the one below) will be removed soon. User details data will be
// injected into the history API responses, so we won't need to fetch user data from other

View file

@ -1,3 +1,4 @@
import _ from 'lodash'
/* eslint-disable
*/
// TODO: This file was created by bulk-decaffeinate.
@ -8,7 +9,7 @@
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
import App from '../../../base'
const historyFileTreeController = function($scope, $element, $attrs, _) {
const historyFileTreeController = function($scope, $element, $attrs) {
const ctrl = this
ctrl.handleEntityClick = file => ctrl.onSelectedFileChange({ file })
ctrl._fileTree = []

View file

@ -10,7 +10,7 @@
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
import App from '../../../base'
const historyLabelController = function($scope, $element, $attrs, $filter, _) {
const historyLabelController = function($scope, $element, $attrs, $filter) {
const ctrl = this
ctrl.$onInit = () => {
if (ctrl.showTooltip == null) {

View file

@ -1,3 +1,4 @@
import _ from 'lodash'
/* eslint-disable
max-len,
*/
@ -12,7 +13,7 @@
import App from '../../../base'
import ColorManager from '../../colors/ColorManager'
import displayNameForUser from '../util/displayNameForUser'
const historyLabelsListController = function($scope, $element, $attrs, _) {
const historyLabelsListController = function($scope, $element, $attrs) {
const ctrl = this
ctrl.isDragging = false
ctrl.versionsWithLabels = []

View file

@ -1,3 +1,4 @@
import _ from 'lodash'
/* eslint-disable
camelcase,
max-len,

View file

@ -1,3 +1,4 @@
import _ from 'lodash'
/* eslint-disable
no-return-assign,
*/

View file

@ -1,3 +1,4 @@
import _ from 'lodash'
/* eslint-disable
handle-callback-err,
max-len,

View file

@ -1,3 +1,4 @@
import _ from 'lodash'
/* eslint-disable
max-len,
no-return-assign,

View file

@ -1,3 +1,4 @@
import _ from 'lodash'
/* eslint-disable
max-len,
no-return-assign,
@ -13,7 +14,7 @@
*/
import App from '../../../base'
export default App.directive('resolvedCommentsDropdown', _ => ({
export default App.directive('resolvedCommentsDropdown', () => ({
restrict: 'E',
templateUrl: 'resolvedCommentsDropdownTemplate',
scope: {

View file

@ -1,3 +1,4 @@
import _ from 'lodash'
/* eslint-disable
camelcase,
max-len,
@ -17,8 +18,7 @@ export default App.controller('SettingsController', function(
$scope,
ExposedSettings,
settings,
ide,
_
ide
) {
const validRootDocExtensions = ExposedSettings.validRootDocExtensions
const validRootDocRegExp = new RegExp(

View file

@ -1,3 +1,4 @@
import _ from 'lodash'
import App from '../../../base'
App.controller('ShareProjectModalController', function(
$scope,

View file

@ -1,3 +1,4 @@
import _ from 'lodash'
/* eslint-disable
max-len,
no-return-assign,

View file

@ -1,3 +1,4 @@
import _ from 'lodash'
/* eslint-disable
max-len,
no-return-assign,
@ -10,8 +11,7 @@ export default App.controller('UserAffiliationsController', function(
$scope,
UserAffiliationsDataService,
$q,
$window,
_
$window
) {
$scope.userEmails = []
$scope.linkedInstitutionIds = []

View file

@ -1,3 +1,4 @@
import _ from 'lodash'
import App from '../../../base'
const countriesList = [
{ code: 'af', name: 'Afghanistan' },
@ -405,7 +406,7 @@ for (let domain of commonDomains) {
}
}
App.factory('UserAffiliationsDataService', function($http, $q, _) {
App.factory('UserAffiliationsDataService', function($http, $q) {
const getCountries = () => $q.resolve(countriesList)
const getDefaultRoleHints = () => $q.resolve(defaultRoleHints)

View file

@ -1,3 +1,4 @@
import _ from 'lodash'
/* eslint-disable
camelcase,
handle-callback-err,
@ -16,12 +17,7 @@
import App from '../base'
import '../directives/mathjax'
import '../services/algolia-search'
App.controller('SearchWikiController', function(
$scope,
algoliaSearch,
_,
$modal
) {
App.controller('SearchWikiController', function($scope, algoliaSearch, $modal) {
$scope.hits = []
$scope.hits_total = 0
$scope.config_hits_per_page = 20

View file

@ -1,3 +1,4 @@
import _ from 'lodash'
/* eslint-disable
camelcase,
max-len,

View file

@ -1,3 +1,4 @@
import _ from 'lodash'
import App from '../../base'
import './services/project-list'
App.controller('ProjectPageController', function(

View file

@ -1,3 +1,4 @@
import _ from 'lodash'
/* eslint-disable
max-len,
no-return-assign,

View file

@ -1,3 +1,4 @@
import _ from 'lodash'
/* global recurly */
/* eslint-disable

View file

@ -1,3 +1,4 @@
import _ from 'lodash'
/* eslint-disable
max-len,
no-return-assign,

View file

@ -1,11 +0,0 @@
/* eslint-disable
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
import '../libraries'
export default angular.module('underscore', []).factory('_', () => window._)

View file

@ -0,0 +1,40 @@
npx jscodeshift \
-t https://gist.githack.com/40thieves/0b495af3fb0ad5fe08915ce5159a2b7b/raw/9c583c0a5b0cbd83a66538a07591b41332efda6a/transform-lodash.js \
--ignore-pattern frontend/js/vendor \
--noSemi=true \
frontend/js
npx jscodeshift \
-t https://gist.githack.com/40thieves/0b495af3fb0ad5fe08915ce5159a2b7b/raw/9c583c0a5b0cbd83a66538a07591b41332efda6a/transform-lodash.js \
--noSemi=true \
test/frontend
for MODULE in admin-panel cms dropbox git-bridge github-sync launchpad metrics open-in-overleaf overleaf-integration portals references-search support templates tpr-webmodule two-factor-authentication v2-templates
do
npx jscodeshift \
-t https://gist.githack.com/40thieves/0b495af3fb0ad5fe08915ce5159a2b7b/raw/9c583c0a5b0cbd83a66538a07591b41332efda6a/transform-lodash.js \
--noSemi=true \
modules/$MODULE/frontend/js
done
npx jscodeshift \
-t https://gist.githack.com/40thieves/0b495af3fb0ad5fe08915ce5159a2b7b/raw/9c583c0a5b0cbd83a66538a07591b41332efda6a/transform-lodash.js \
--noSemi=true \
modules/rich-text/frontend/js
npx jscodeshift \
-t https://gist.githack.com/40thieves/0b495af3fb0ad5fe08915ce5159a2b7b/raw/9c583c0a5b0cbd83a66538a07591b41332efda6a/transform-lodash.js \
--noSemi=true \
modules/rich-text/test/frontend
npx jscodeshift \
-t https://gist.githack.com/40thieves/0b495af3fb0ad5fe08915ce5159a2b7b/raw/9c583c0a5b0cbd83a66538a07591b41332efda6a/transform-lodash.js \
--noSemi=true \
modules/publish-modal/frontend/js
npx jscodeshift \
-t https://gist.githack.com/40thieves/0b495af3fb0ad5fe08915ce5159a2b7b/raw/9c583c0a5b0cbd83a66538a07591b41332efda6a/transform-lodash.js \
--noSemi=true \
modules/publish-modal/test/frontend
make format_fix

View file

@ -181,16 +181,6 @@ module.exports = {
options: 'angular'
}
]
},
{
// Expose lodash global variable
test: require.resolve('lodash'),
use: [
{
loader: 'expose-loader',
options: '_'
}
]
}
]
},