Merge pull request #409 from toasted-nutbread/update-global-declaration-format

Update global declaration format
This commit is contained in:
toasted-nutbread 2020-03-14 13:48:50 -04:00 committed by GitHub
commit 1cacbb6202
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
39 changed files with 399 additions and 71 deletions

View File

@ -63,7 +63,7 @@
"semi-spacing": ["error", {"before": false, "after": true}], "semi-spacing": ["error", {"before": false, "after": true}],
"space-in-parens": ["error", "never"], "space-in-parens": ["error", "never"],
"space-unary-ops": "error", "space-unary-ops": "error",
"spaced-comment": ["error", "always", {"markers": ["global"]}], "spaced-comment": ["error", "always"],
"switch-colon-spacing": ["error", {"after": true, "before": false}], "switch-colon-spacing": ["error", {"after": true, "before": false}],
"template-curly-spacing": ["error", "never"], "template-curly-spacing": ["error", "never"],
"template-tag-spacing": ["error", "never"], "template-tag-spacing": ["error", "never"],

View File

@ -16,7 +16,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
/*global requestJson*/ /* global
* requestJson
*/
/* /*
* AnkiConnect * AnkiConnect

View File

@ -16,7 +16,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
/*global jpIsStringEntirelyKana*/ /* global
* jpIsStringEntirelyKana
*/
class AudioUriBuilder { class AudioUriBuilder {
constructor() { constructor() {

View File

@ -16,13 +16,32 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
/*global optionsSave, utilIsolate /* global
conditionsTestValue, profileConditionsDescriptor * AnkiConnect
handlebarsRenderDynamic * AnkiNoteBuilder
requestText, requestJson, optionsLoad * AnkiNull
dictConfigured, dictTermsSort, dictEnabledSet * AudioSystem
jpConvertReading, jpDistributeFuriganaInflected, jpKatakanaToHiragana * AudioUriBuilder
AnkiNoteBuilder, AudioSystem, AudioUriBuilder, Translator, AnkiConnect, AnkiNull, Mecab, BackendApiForwarder, JsonSchema, ClipboardMonitor*/ * BackendApiForwarder
* ClipboardMonitor
* JsonSchema
* Mecab
* Translator
* conditionsTestValue
* dictConfigured
* dictEnabledSet
* dictTermsSort
* handlebarsRenderDynamic
* jpConvertReading
* jpDistributeFuriganaInflected
* jpKatakanaToHiragana
* optionsLoad
* optionsSave
* profileConditionsDescriptor
* requestJson
* requestText
* utilIsolate
*/
class Backend { class Backend {
constructor() { constructor() {

View File

@ -16,7 +16,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
/*global jpIsStringPartiallyJapanese*/ /* global
* jpIsStringPartiallyJapanese
*/
class ClipboardMonitor extends EventDispatcher { class ClipboardMonitor extends EventDispatcher {
constructor({getClipboard}) { constructor({getClipboard}) {

View File

@ -16,7 +16,11 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
/*global apiCommandExec, apiGetEnvironmentInfo, apiOptionsGet*/ /* global
* apiCommandExec
* apiGetEnvironmentInfo
* apiOptionsGet
*/
function showExtensionInfo() { function showExtensionInfo() {
const node = document.getElementById('extension-info'); const node = document.getElementById('extension-info');

View File

@ -16,7 +16,12 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
/*global dictFieldSplit, requestJson, JsonSchema, JSZip*/ /* global
* JSZip
* JsonSchema
* dictFieldSplit
* requestJson
*/
class Database { class Database {
constructor() { constructor() {

View File

@ -16,7 +16,11 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
/*global jpIsCodePointKanji, jpDistributeFurigana, Handlebars*/ /* global
* Handlebars
* jpDistributeFurigana
* jpIsCodePointKanji
*/
function handlebarsEscape(text) { function handlebarsEscape(text) {
return Handlebars.Utils.escapeExpression(text); return Handlebars.Utils.escapeExpression(text);

View File

@ -16,7 +16,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
/*global wanakana*/ /* global
* wanakana
*/
const JP_HALFWIDTH_KATAKANA_MAPPING = new Map([ const JP_HALFWIDTH_KATAKANA_MAPPING = new Map([
['ヲ', 'ヲヺ-'], ['ヲ', 'ヲヺ-'],

View File

@ -16,7 +16,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
/*global utilStringHashCode*/ /* global
* utilStringHashCode
*/
/* /*
* Generic options functions * Generic options functions

View File

@ -16,7 +16,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
/*global apiOptionsGet*/ /* global
* apiOptionsGet
*/
async function searchFrontendSetup() { async function searchFrontendSetup() {
await yomichan.prepare(); await yomichan.prepare();

View File

@ -16,7 +16,10 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
/*global apiGetQueryParserTemplatesHtml, TemplateHandler*/ /* global
* TemplateHandler
* apiGetQueryParserTemplatesHtml
*/
class QueryParserGenerator { class QueryParserGenerator {
constructor() { constructor() {

View File

@ -16,7 +16,15 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
/*global apiTermsFind, apiOptionsSet, apiTextParse, apiTextParseMecab, TextScanner, QueryParserGenerator, docSentenceExtract*/ /* global
* QueryParserGenerator
* TextScanner
* apiOptionsSet
* apiTermsFind
* apiTextParse
* apiTextParseMecab
* docSentenceExtract
*/
class QueryParser extends TextScanner { class QueryParser extends TextScanner {
constructor(search) { constructor(search) {

View File

@ -16,7 +16,14 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
/*global apiOptionsSet, apiTermsFind, apiClipboardGet, Display, QueryParser, ClipboardMonitor*/ /* global
* ClipboardMonitor
* Display
* QueryParser
* apiClipboardGet
* apiOptionsSet
* apiTermsFind
*/
class DisplaySearch extends Display { class DisplaySearch extends Display {
constructor() { constructor() {

View File

@ -16,10 +16,18 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
/*global getOptionsContext, getOptionsMutable, settingsSaveOptions /* global
ankiGetFieldMarkers, ankiGetFieldMarkersHtml * AnkiNoteBuilder
apiOptionsGet, apiTermsFind, apiGetDefaultAnkiFieldTemplates, apiTemplateRender * ankiGetFieldMarkers
AnkiNoteBuilder*/ * ankiGetFieldMarkersHtml
* apiGetDefaultAnkiFieldTemplates
* apiOptionsGet
* apiTemplateRender
* apiTermsFind
* getOptionsContext
* getOptionsMutable
* settingsSaveOptions
*/
function onAnkiFieldTemplatesReset(e) { function onAnkiFieldTemplatesReset(e) {
e.preventDefault(); e.preventDefault();

View File

@ -16,9 +16,16 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
/*global getOptionsContext, getOptionsMutable, settingsSaveOptions /* global
utilBackgroundIsolate, utilAnkiGetDeckNames, utilAnkiGetModelNames, utilAnkiGetModelFieldNames * getOptionsContext
onFormOptionsChanged*/ * getOptionsMutable
* onFormOptionsChanged
* settingsSaveOptions
* utilAnkiGetDeckNames
* utilAnkiGetModelFieldNames
* utilAnkiGetModelNames
* utilBackgroundIsolate
*/
// Private // Private

View File

@ -16,8 +16,14 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
/*global getOptionsContext, getOptionsMutable, settingsSaveOptions, apiAudioGetUri /* global
AudioSystem, AudioSourceUI*/ * AudioSourceUI
* AudioSystem
* apiAudioGetUri
* getOptionsContext
* getOptionsMutable
* settingsSaveOptions
*/
let audioSourceUI = null; let audioSourceUI = null;
let audioSystem = null; let audioSystem = null;

View File

@ -16,9 +16,17 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
/*global apiOptionsGetFull, apiGetEnvironmentInfo, apiGetDefaultAnkiFieldTemplates /* global
utilBackend, utilIsolate, utilBackgroundIsolate, utilReadFileArrayBuffer * apiGetDefaultAnkiFieldTemplates
optionsGetDefault, optionsUpdateVersion*/ * apiGetEnvironmentInfo
* apiOptionsGetFull
* optionsGetDefault
* optionsUpdateVersion
* utilBackend
* utilBackgroundIsolate
* utilIsolate
* utilReadFileArrayBuffer
*/
// Exporting // Exporting

View File

@ -16,7 +16,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
/*global conditionsNormalizeOptionValue*/ /* global
* conditionsNormalizeOptionValue
*/
class ConditionsUI { class ConditionsUI {
static instantiateTemplate(templateSelector) { static instantiateTemplate(templateSelector) {

View File

@ -16,11 +16,23 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
/*global getOptionsContext, getOptionsMutable, getOptionsFullMutable, settingsSaveOptions, apiOptionsGetFull, apiOptionsGet /* global
utilBackgroundIsolate, utilDatabaseDeleteDictionary, utilDatabaseGetDictionaryInfo, utilDatabaseGetDictionaryCounts * PageExitPrevention
utilDatabasePurge, utilDatabaseImport * apiOptionsGet
storageUpdateStats, storageEstimate * apiOptionsGetFull
PageExitPrevention*/ * getOptionsContext
* getOptionsFullMutable
* getOptionsMutable
* settingsSaveOptions
* storageEstimate
* storageUpdateStats
* utilBackgroundIsolate
* utilDatabaseDeleteDictionary
* utilDatabaseGetDictionaryCounts
* utilDatabaseGetDictionaryInfo
* utilDatabaseImport
* utilDatabasePurge
*/
let dictionaryUI = null; let dictionaryUI = null;

View File

@ -16,12 +16,25 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
/*global getOptionsContext, apiOptionsSave /* global
utilBackend, utilIsolate, utilBackgroundIsolate * ankiErrorShown
ankiErrorShown, ankiFieldsToDict * ankiFieldsToDict
ankiTemplatesUpdateValue, onAnkiOptionsChanged, onDictionaryOptionsChanged * ankiInitialize
appearanceInitialize, audioSettingsInitialize, profileOptionsSetup, dictSettingsInitialize * ankiTemplatesInitialize
ankiInitialize, ankiTemplatesInitialize, storageInfoInitialize, backupInitialize * ankiTemplatesUpdateValue
* apiOptionsSave
* appearanceInitialize
* audioSettingsInitialize
* backupInitialize
* dictSettingsInitialize
* getOptionsContext
* onAnkiOptionsChanged
* onDictionaryOptionsChanged
* profileOptionsSetup
* storageInfoInitialize
* utilBackend
* utilBackgroundIsolate
* utilIsolate
*/ */
function getOptionsMutable(optionsContext) { function getOptionsMutable(optionsContext) {

View File

@ -16,7 +16,13 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
/*global apiOptionsGet, Popup, PopupProxyHost, Frontend, TextSourceRange*/ /* global
* Frontend
* Popup
* PopupProxyHost
* TextSourceRange
* apiOptionsGet
*/
class SettingsPopupPreview { class SettingsPopupPreview {
constructor() { constructor() {

View File

@ -16,9 +16,17 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
/*global getOptionsMutable, getOptionsFullMutable, settingsSaveOptions, apiOptionsGetFull /* global
utilBackgroundIsolate, formWrite * ConditionsUI
conditionsClearCaches, ConditionsUI, profileConditionsDescriptor*/ * apiOptionsGetFull
* conditionsClearCaches
* formWrite
* getOptionsFullMutable
* getOptionsMutable
* profileConditionsDescriptor
* settingsSaveOptions
* utilBackgroundIsolate
*/
let currentProfileIndex = 0; let currentProfileIndex = 0;
let profileConditionsContainer = null; let profileConditionsContainer = null;

View File

@ -16,7 +16,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
/*global apiGetEnvironmentInfo*/ /* global
* apiGetEnvironmentInfo
*/
function storageBytesToLabeledString(size) { function storageBytesToLabeledString(size) {
const base = 1000; const base = 1000;

View File

@ -16,12 +16,28 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
/*global requestJson /* global
dictTermsMergeBySequence, dictTagBuildSource, dictTermsMergeByGloss, dictTermsSort, dictTagsSort * Database
dictEnabledSet, dictTermsGroup, dictTermsCompressTags, dictTermsUndupe, dictTagSanitize * Deinflector
jpDistributeFurigana, jpConvertHalfWidthKanaToFullWidth, jpConvertNumericTofullWidth * dictEnabledSet
jpConvertAlphabeticToKana, jpHiraganaToKatakana, jpKatakanaToHiragana, jpIsCodePointJapanese * dictTagBuildSource
Database, Deinflector*/ * dictTagSanitize
* dictTagsSort
* dictTermsCompressTags
* dictTermsGroup
* dictTermsMergeByGloss
* dictTermsMergeBySequence
* dictTermsSort
* dictTermsUndupe
* jpConvertAlphabeticToKana
* jpConvertHalfWidthKanaToFullWidth
* jpConvertNumericTofullWidth
* jpDistributeFurigana
* jpHiraganaToKatakana
* jpIsCodePointJapanese
* jpKatakanaToHiragana
* requestJson
*/
class Translator { class Translator {
constructor() { constructor() {

View File

@ -16,7 +16,11 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
/*global TextSourceElement, TextSourceRange, DOM*/ /* global
* DOM
* TextSourceElement
* TextSourceRange
*/
const REGEX_TRANSPARENT_COLOR = /rgba\s*\([^)]*,\s*0(?:\.0+)?\s*\)/; const REGEX_TRANSPARENT_COLOR = /rgba\s*\([^)]*,\s*0(?:\.0+)?\s*\)/;

View File

@ -16,7 +16,12 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
/*global popupNestedInitialize, apiForward, apiGetMessageToken, Display*/ /* global
* Display
* apiForward
* apiGetMessageToken
* popupNestedInitialize
*/
class DisplayFloat extends Display { class DisplayFloat extends Display {
constructor() { constructor() {

View File

@ -16,7 +16,11 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
/*global PopupProxyHost, PopupProxy, Frontend*/ /* global
* Frontend
* PopupProxy
* PopupProxyHost
*/
async function main() { async function main() {
await yomichan.prepare(); await yomichan.prepare();

View File

@ -16,7 +16,14 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
/*global apiGetZoom, apiOptionsGet, apiTermsFind, apiKanjiFind, docSentenceExtract, TextScanner*/ /* global
* TextScanner
* apiGetZoom
* apiKanjiFind
* apiOptionsGet
* apiTermsFind
* docSentenceExtract
*/
class Frontend extends TextScanner { class Frontend extends TextScanner {
constructor(popup, ignoreNodes) { constructor(popup, ignoreNodes) {

View File

@ -16,7 +16,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
/*global apiOptionsGet*/ /* global
* apiOptionsGet
*/
let popupNestedInitialized = false; let popupNestedInitialized = false;

View File

@ -16,7 +16,11 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
/*global apiFrameInformationGet, FrontendApiReceiver, Popup*/ /* global
* FrontendApiReceiver
* Popup
* apiFrameInformationGet
*/
class PopupProxyHost { class PopupProxyHost {
constructor() { constructor() {

View File

@ -16,7 +16,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
/*global FrontendApiSender*/ /* global
* FrontendApiSender
*/
class PopupProxy { class PopupProxy {
constructor(id, depth, parentId, parentFrameId, url) { constructor(id, depth, parentId, parentFrameId, url) {

View File

@ -16,7 +16,10 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
/*global apiInjectStylesheet, apiGetMessageToken*/ /* global
* apiGetMessageToken
* apiInjectStylesheet
*/
class Popup { class Popup {
constructor(id, depth, frameIdPromise) { constructor(id, depth, frameIdPromise) {

View File

@ -16,7 +16,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
/*global apiGetDisplayTemplatesHtml, TemplateHandler*/ /* global
* TemplateHandler
* apiGetDisplayTemplatesHtml
*/
class DisplayGenerator { class DisplayGenerator {
constructor() { constructor() {

View File

@ -16,10 +16,24 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
/*global docRangeFromPoint, docSentenceExtract /* global
apiKanjiFind, apiTermsFind, apiNoteView, apiOptionsGet, apiDefinitionsAddable, apiDefinitionAdd * AudioSystem
apiScreenshotGet, apiForward, apiAudioGetUri * DOM
AudioSystem, DisplayGenerator, WindowScroll, DisplayContext, DOM*/ * DisplayContext
* DisplayGenerator
* WindowScroll
* apiAudioGetUri
* apiDefinitionAdd
* apiDefinitionsAddable
* apiForward
* apiKanjiFind
* apiNoteView
* apiOptionsGet
* apiScreenshotGet
* apiTermsFind
* docRangeFromPoint
* docSentenceExtract
*/
class Display { class Display {
constructor(spinner, container) { constructor(spinner, container) {

View File

@ -16,7 +16,11 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
/*global docRangeFromPoint, TextSourceRange, DOM*/ /* global
* DOM
* TextSourceRange
* docRangeFromPoint
*/
class TextScanner { class TextScanner {
constructor(node, ignoreNodes, ignoreElements, ignorePoints) { constructor(node, ignoreNodes, ignoreElements, ignorePoints) {

View File

@ -7,7 +7,7 @@
}, },
"scripts": { "scripts": {
"test": "npm run test-lint && npm run test-code", "test": "npm run test-lint && npm run test-code",
"test-lint": "eslint .", "test-lint": "eslint . && node ./test/lint/global-declarations.js",
"test-code": "node ./test/test-schema.js && node ./test/test-dictionary.js && node ./test/test-database.js && node ./test/test-document.js" "test-code": "node ./test/test-schema.js && node ./test/test-dictionary.js && node ./test/test-database.js && node ./test/test-document.js"
}, },
"repository": { "repository": {

View File

@ -0,0 +1,105 @@
/*
* Copyright (C) 2020 Alex Yatskov <alex@foosoft.net>
* Author: Alex Yatskov <alex@foosoft.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
const fs = require('fs');
const path = require('path');
const assert = require('assert');
const {getAllFiles} = require('../yomichan-test');
function countOccurences(string, pattern) {
return (string.match(pattern) || []).length;
}
function getNewline(string) {
const count1 = countOccurences(string, /(?:^|[^\r])\n/g);
const count2 = countOccurences(string, /\r\n/g);
const count3 = countOccurences(string, /\r(?:[^\n]|$)/g);
if (count2 > count1) {
return (count3 > count2) ? '\r' : '\r\n';
} else {
return (count3 > count1) ? '\r' : '\n';
}
}
function validateGlobals(fileName, fix) {
const pattern = /\/\*\s*global\s+([\w\W]*?)\*\//g;
const trimPattern = /^[\s,*]+|[\s,*]+$/g;
const splitPattern = /[\s,*]+/;
const source = fs.readFileSync(fileName, {encoding: 'utf8'});
let match;
let first = true;
let endIndex = 0;
let newSource = '';
const newline = getNewline(source);
while ((match = pattern.exec(source)) !== null) {
if (!first) {
console.error(`Encountered more than one global declaration in ${fileName}`);
return false;
}
first = false;
const parts = match[1].replace(trimPattern, '').split(splitPattern);
parts.sort();
const actual = match[0];
const expected = `/* global${parts.map((v) => `${newline} * ${v}`).join('')}${newline} */`;
try {
assert.strictEqual(actual, expected);
} catch (e) {
console.error(`Global declaration error encountered in ${fileName}:`);
console.error(e.message);
if (!fix) {
return false;
}
}
newSource += source.substring(0, match.index);
newSource += expected;
endIndex = match.index + match[0].length;
}
newSource += source.substring(endIndex);
if (fix) {
fs.writeFileSync(fileName, newSource, {encoding: 'utf8'});
}
return true;
}
function main() {
const fix = (process.argv.length >= 2 && process.argv[2] === '--fix');
const directory = path.resolve(__dirname, '..', '..', 'ext');
const pattern = /\.js$/;
const ignorePattern = /[\\/]ext[\\/]mixed[\\/]lib[\\/]/;
const fileNames = getAllFiles(directory, (f) => pattern.test(f) && !ignorePattern.test(f));
for (const fileName of fileNames) {
if (!validateGlobals(fileName, fix)) {
process.exit(-1);
return;
}
}
process.exit(0);
}
if (require.main === module) { main(); }

View File

@ -50,8 +50,29 @@ function createTestDictionaryArchive(dictionary, dictionaryName) {
return archive; return archive;
} }
function getAllFiles(baseDirectory, predicate=null) {
const results = [];
const directories = [path.resolve(baseDirectory)];
while (directories.length > 0) {
const directory = directories.shift();
for (const fileName of fs.readdirSync(directory)) {
const fullFileName = path.resolve(directory, fileName);
const stats = fs.statSync(fullFileName);
if (stats.isFile()) {
if (typeof predicate !== 'function' || predicate(fullFileName, directory, baseDirectory)) {
results.push(fullFileName);
}
} else if (stats.isDirectory()) {
directories.push(fullFileName);
}
}
}
return results;
}
module.exports = { module.exports = {
createTestDictionaryArchive, createTestDictionaryArchive,
getAllFiles,
get JSZip() { return getJSZip(); } get JSZip() { return getJSZip(); }
}; };