Skip to content

Commit

Permalink
fix: add missing 'use strict'; directives (#5722)
Browse files Browse the repository at this point in the history
* fix: add missing `'use strict';` directives

`'use strict';` is 15 years old, it's time we catch up :)

Commit created via

```sh
for f in $( git ls-files | grep '.js$' ); do
  grep -q 'use strict' "$f" || \
  ( head -n5 "$f" | grep -Eq '(im|ex)port ' ) || \
  ( \
    (( head -n1 "$f" | grep -q '#!' ) && \
      ( cat "$f" | sed -e '/#!/s/$/\n'"'use strict';"'/' ) || \
      ( echo "'use strict';" && cat "$f" ) )  > "${f}~" && \
    mv -v "${f}~" "$f" &&  \
    rm -f "${f}~") ;
  done ; npm run bootstrap && (cd packages/bson-transpilers && npm run compile)
```

* fixup: add missing use strict to create-workspace.js

* fixup: account for clashes with legacy linting rules in bson-transpilers and hadron-build
  • Loading branch information
addaleax authored Apr 24, 2024
1 parent 91bd2c5 commit 0ebcfc7
Show file tree
Hide file tree
Showing 262 changed files with 289 additions and 35 deletions.
1 change: 1 addition & 0 deletions configs/eslint-plugin-compass/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
module.exports = {
root: true,
extends: ['@mongodb-js/eslint-config-compass'],
Expand Down
1 change: 1 addition & 0 deletions configs/eslint-plugin-compass/.mocharc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
module.exports = {
...require('@mongodb-js/mocha-config-compass'),
spec: ['rules/**/*.test.js'],
Expand Down
1 change: 1 addition & 0 deletions configs/eslint-plugin-compass/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
module.exports = {
rules: {
'no-leafygreen-outside-compass-components': require('./rules/no-leafygreen-outside-compass-components'),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
const path = require('path');

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
const { RuleTester } = require('eslint');
const path = require('path');
const rule = require('./no-leafygreen-outside-compass-components');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
const path = require('path');
const { spawnSync } = require('child_process');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
const { RuleTester } = require('eslint');
const path = require('path');
const rule = require('./unique-mongodb-log-id');
Expand Down
1 change: 1 addition & 0 deletions configs/eslint-plugin-compass/test/__fixtures__/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
/* eslint-disable @mongodb-js/compass/unique-mongodb-log-id */
/* global mongoLogId */
mongoLogId(1);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
let setupPreferencesPromise;

module.exports = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
// Not implemented in jsdom
if (!window.matchMedia) {
window.matchMedia = globalThis.matchMedia = (media) => {
Expand Down
1 change: 1 addition & 0 deletions configs/mocha-config-compass/register/leaflet-register.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
// Proxy window.L between window and globalThis for leaflet/leaflet-draw compatibility
if (typeof window !== undefined && window !== globalThis) {
Object.defineProperty(window, 'L', {
Expand Down
1 change: 1 addition & 0 deletions configs/mocha-config-compass/register/node-env-register.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
'use strict';
process.env.NODE_ENV = 'test';
1 change: 1 addition & 0 deletions configs/mocha-config-compass/reporter.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
const Mocha = require('mocha');
const fs = require('fs');
const path = require('path');
Expand Down
1 change: 1 addition & 0 deletions configs/prettier-config-compass/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
module.exports = {
...require('@mongodb-js/prettier-config-devtools'),
};
1 change: 1 addition & 0 deletions configs/webpack-config-compass/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
module.exports = {
root: true,
extends: ['@mongodb-js/eslint-config-compass'],
Expand Down
1 change: 1 addition & 0 deletions configs/webpack-config-compass/bin/webpack.js
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env node
'use strict';

// XXX: This mimics (simplified) webpack behavior, but makes sure that we are
// always resolving webpack-cli relative to the config. It is required to do, to
Expand Down
1 change: 1 addition & 0 deletions packages/atlas-service/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
module.exports = {
root: true,
extends: ['@mongodb-js/eslint-config-compass'],
Expand Down
1 change: 1 addition & 0 deletions packages/atlas-service/.mocharc.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
'use strict';
module.exports = require('@mongodb-js/mocha-config-compass/compass-plugin');
1 change: 1 addition & 0 deletions packages/atlas-service/main.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
'use strict';
module.exports = require('./dist/main');
1 change: 1 addition & 0 deletions packages/atlas-service/renderer.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
'use strict';
module.exports = require('./dist/renderer');
7 changes: 3 additions & 4 deletions packages/bson-transpilers/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
"es6": true
},
"rules": {
"camelcase": 1
"camelcase": 1,
"filename-rules/match": 0
},
"extends": [
"mongodb-js/node"
]
"extends": ["@mongodb-js/eslint-config-compass/plugin"]
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
/* eslint complexity: 0, camelcase: 0, "new-cap": 0 */
const {
BsonTranspilersAttributeError,
Expand Down Expand Up @@ -466,7 +467,7 @@ module.exports = (ANTLRVisitor) => class CodeGenerationVisitor extends ANTLRVisi
type = this.Types[type];
}
while (type !== null) {
if (!(type.attr.hasOwnProperty(rhs))) {
if (!(Object.prototype.hasOwnProperty.call(type.attr, rhs))) {
if (type.id in this.BsonTypes && this.BsonTypes[type.id].id !== null) { // TODO: tell symbols vs types
throw new BsonTranspilersAttributeError(
`'${rhs}' not an attribute of ${type.id}`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
/**
* Stores declarations for use in the DriverTemplate
*
Expand Down
1 change: 1 addition & 0 deletions packages/bson-transpilers/codegeneration/ErrorListener.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
const antlr4 = require('antlr4');

const { BsonTranspilersSyntaxError } = require('../helper/error');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
/*
* Class for handling edge cases for csharp code generation. Defines "emit" methods.
*/
Expand Down
1 change: 1 addition & 0 deletions packages/bson-transpilers/codegeneration/go/Generator.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
/*
* Class for handling edge cases for Go code generation. Defines "emit" methods.
*/
Expand Down
1 change: 1 addition & 0 deletions packages/bson-transpilers/codegeneration/java/Generator.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
/* eslint complexity: 0 */
const {doubleQuoteStringify, removeQuotes} = require('../../helper/format');
const {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
/*
* Class for handling edge cases for node code generation. Defines "emit" methods.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
/* eslint complexity: 0 */
const vm = require('vm');
const bson = require('bson');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
/* eslint new-cap: 0 camelcase: 0 */
const bson = require('bson');
const {
Expand Down
1 change: 1 addition & 0 deletions packages/bson-transpilers/codegeneration/php/Generator.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
/*
* Class for handling edge cases for php code generation. Defines "emit" methods.
*/
Expand Down
1 change: 1 addition & 0 deletions packages/bson-transpilers/codegeneration/php/PHPUtils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
/**
* Common functions to use in PHP templates
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
/*
* Class for handling edge cases for python code generation. Defines "emit" methods.
*/
Expand Down
1 change: 1 addition & 0 deletions packages/bson-transpilers/codegeneration/python/Visitor.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
/* eslint camelcase: 0 complexity: 0*/
const vm = require('vm');
const {
Expand Down
1 change: 1 addition & 0 deletions packages/bson-transpilers/codegeneration/ruby/Generator.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
/*
* Class for handling edge cases for ruby code generation. Defines "emit" methods.
*/
Expand Down
1 change: 1 addition & 0 deletions packages/bson-transpilers/codegeneration/rust/Generator.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
/*
* Class for handling edge cases for rust code generation. Defines "emit" methods.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
/*
* Class for handling edge cases for shell code generation. Defines "emit" methods.
*/
Expand Down
1 change: 1 addition & 0 deletions packages/bson-transpilers/codegeneration/shell/Visitor.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
/* eslint complexity: 0 */
const vm = require('vm');
const bson = require('bson');
Expand Down
1 change: 1 addition & 0 deletions packages/bson-transpilers/compile-symbol-table.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
/* eslint-disable no-sync */
const path = require('path');

Expand Down
1 change: 1 addition & 0 deletions packages/bson-transpilers/download-antlr.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
/* eslint-disable no-console */
/* eslint-disable no-sync */

Expand Down
1 change: 1 addition & 0 deletions packages/bson-transpilers/helper/error.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
const config = require('../config/error.json');
const errors = {};

Expand Down
1 change: 1 addition & 0 deletions packages/bson-transpilers/helper/format.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
/**
* Takes in an identifier that may or may not be a string and returns a string
* with double quotes. Replace any non-escaped double quotes with \"
Expand Down
1 change: 1 addition & 0 deletions packages/bson-transpilers/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
const antlr4 = require('antlr4');
const ECMAScriptLexer = require('./lib/antlr/ECMAScriptLexer.js');
const ECMAScriptParser = require('./lib/antlr/ECMAScriptParser.js');
Expand Down
2 changes: 1 addition & 1 deletion packages/bson-transpilers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
},
"license": "SSPL",
"devDependencies": {
"@mongodb-js/eslint-config-compass": "^1.1.0",
"chai": "^4.3.4",
"depcheck": "^1.4.1",
"eslint": "^7.25.0",
"eslint-config-mongodb-js": "^2.1.0",
"mocha": "^10.2.0"
},
"dependencies": {
Expand Down
1 change: 1 addition & 0 deletions packages/bson-transpilers/printers/ECMAScriptListener.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
const antlr4 = require('antlr4');
const ECMAScriptListener = require('../lib/ECMAScriptListener.js');

Expand Down
7 changes: 4 additions & 3 deletions packages/bson-transpilers/test/casting.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
/* eslint new-cap: 0 no-sync: 0 */
const path = require('path');
const fs = require('fs');
Expand Down Expand Up @@ -29,7 +30,7 @@ const readYAML = (filename) => {
return parseResult;
};

describe('Casting tests', () => {
describe('Casting tests', function() {
if (modes.length > 0 && modes.indexOf('casting') === -1) {
return;
}
Expand Down Expand Up @@ -63,8 +64,8 @@ describe('Casting tests', () => {
doc.BsonSymbols, doc.NativeSymbols);
transpiler.Syntax = doc.Syntax;
transpiler.SYMBOL_TYPE = doc.SymbolTypes;
describe(`from ${input} to ${output}`, () => {
it(test.description, () => {
describe(`from ${input} to ${output}`, function() {
it(test.description, function() {
if (test.input[input].args) {
transpiler.Symbols.TestFunc.args = test.input[input].args.map((t) => {
return t.map((k) => ( k !== null ? transpiler.Types[k] : k ));
Expand Down
19 changes: 10 additions & 9 deletions packages/bson-transpilers/test/declaration-store.test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
'use strict';
const assert = require('assert');
const DeclarationStore = require('../codegeneration/DeclarationStore');

describe('DeclarationStore', () => {
it('adds data using #add', () => {
describe('DeclarationStore', function() {
it('adds data using #add', function() {
const ds = new DeclarationStore();

ds.addVar('Temp', 'objectID', (varName) => { return `objectId${varName}`; });
assert.strictEqual(ds.length(), 1);
});
it('returns incremented variable names given the pre-incremented variable root-name', () => {
it('returns incremented variable names given the pre-incremented variable root-name', function() {
const ds = new DeclarationStore();

ds.addVar('ForTemp', 'objectID', () => { return 1; });
Expand All @@ -20,7 +21,7 @@ describe('DeclarationStore', () => {
ds.addVar('ForTemp', 'objectID', () => { return 3; });
assert.strictEqual(ds.next('ForTemp', 'objectID'), 'objectIDForTemp3');
});
it('stringifies multiple variables declarations', () => {
it('stringifies multiple variables declarations', function() {
const ds = new DeclarationStore();
const declaration1 = (varName) => {
return []
Expand Down Expand Up @@ -55,7 +56,7 @@ describe('DeclarationStore', () => {
.join('\n');
assert.strictEqual(ds.toString(), expected);
});
it('skips defining declarations for multiple of the exact same declaration (1)', () => {
it('skips defining declarations for multiple of the exact same declaration (1)', function() {
const ds = new DeclarationStore();
const declaration1 = (varName) => {
return []
Expand Down Expand Up @@ -101,7 +102,7 @@ describe('DeclarationStore', () => {
.join('\n');
assert.strictEqual(ds.toString(), expected);
});
it('skips defining declarations for multiple of the exact same declaration (2)', () => {
it('skips defining declarations for multiple of the exact same declaration (2)', function() {
const ds = new DeclarationStore();
const declaration1 = (varName) => {
return []
Expand Down Expand Up @@ -147,7 +148,7 @@ describe('DeclarationStore', () => {
.join('\n');
assert.strictEqual(ds.toString(), expected);
});
it('ignores duplications over different variables', () => {
it('ignores duplications over different variables', function() {
const ds = new DeclarationStore();
const declaration1 = (varName) => {
return []
Expand Down Expand Up @@ -198,7 +199,7 @@ describe('DeclarationStore', () => {
.join('\n');
assert.strictEqual(ds.toString(), expected);
});
it('ignores duplications over different functions', () => {
it('ignores duplications over different functions', function() {
const ds = new DeclarationStore();
const declaration1 = 'var x := func() {}';
const declaration2 = 'var x := func() {}';
Expand All @@ -215,7 +216,7 @@ describe('DeclarationStore', () => {
.join('\n');
assert.strictEqual(ds.toString(), expected);
});
it('get length of sets', () => {
it('get length of sets', function() {
const ds = new DeclarationStore();
const declaration1 = 'var x := func() {}';
const declaration2 = 'var x := func() {}';
Expand Down
13 changes: 7 additions & 6 deletions packages/bson-transpilers/test/functions.test.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
'use strict';
const bsonTranspilers = require('..');
const assert = require('assert');

const {
BsonTranspilersUnimplementedError
} = require('../helper/error');

describe('function expressions (shell)', () => {
it('compiles functions to javascript', () => {
describe('function expressions (shell)', function() {
it('compiles functions to javascript', function() {
assert.strictEqual(
bsonTranspilers.shell.javascript.compile('function(){ return this.x === 1 }'),
'function(){ return this.x === 1 }'
);
});

it('compiles functions to javascript (takes the right source range)', () => {
it('compiles functions to javascript (takes the right source range)', function() {
assert.strictEqual(
bsonTranspilers.shell.javascript.compile('1 + function(){ return this.x === 1 }'),
'1 + function(){ return this.x === 1 }'
);
});

it('compiles functions to javascript (preserve new lines)', () => {
it('compiles functions to javascript (preserve new lines)', function() {
assert.strictEqual(
bsonTranspilers.shell.javascript.compile(`function(){
return this.x === 1
Expand All @@ -31,7 +32,7 @@ describe('function expressions (shell)', () => {
);
});

it('allows functions in pipeline stages', () => {
it('allows functions in pipeline stages', function() {
assert.strictEqual(
bsonTranspilers.shell.javascript.compile(`{
$match: {
Expand All @@ -47,7 +48,7 @@ describe('function expressions (shell)', () => {
});

['object', 'csharp', 'java', 'python', 'ruby', 'rust', 'php'].forEach((language) => {
it(`throws an unsupported error compiling functions to ${language}`, () => {
it(`throws an unsupported error compiling functions to ${language}`, function() {
assert.throws(
() => {
bsonTranspilers.shell[language].compile('function(){}');
Expand Down
1 change: 1 addition & 0 deletions packages/bson-transpilers/test/index.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
const assert = require('assert');
const transpilers = require('../index');

Expand Down
Loading

0 comments on commit 0ebcfc7

Please sign in to comment.