Skip to content

Fix eslint warnings #4923

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 17, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## UNRELEASED

### Fixes

* Fixes all eslint warnings.

## 4.15.0 (2025-04-16)

### Adds
Expand Down
4 changes: 2 additions & 2 deletions defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ module.exports = {
'@apostrophecms/oembed': {},
'@apostrophecms/pager': {},
'@apostrophecms/any-doc-type': {},
// global comes first so it can register a doc type manager and clean things up before
// pages claims any orphan page types
// global comes first so it can register a doc type manager and clean
// things up before pages claims any orphan page types
'@apostrophecms/global': {},
'@apostrophecms/polymorphic-type': {},
'@apostrophecms/page': {},
Expand Down
61 changes: 39 additions & 22 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,25 @@ let defaults = require('./defaults.js');
//
// `openTelemetryProvider`
//
// If set, Apostrophe will register it as a global OpenTelemetry tracer provider.
// The expected value is an object, an instance of TracerProvider.
// If the Node SDK is used in the application instead of manual configuration,
// the provider instance is only available as a
// private property: `sdkInstance._tracerProvider`. An issue can be opened
// to discuss the exposure of a public getter with the OpenTelemetry developers.
// If set, Apostrophe will register it as a global OpenTelemetry tracer
// provider. The expected value is an object, an instance of TracerProvider. If
// the Node SDK is used in the application instead of manual configuration, the
// provider instance is only available as a private property:
// `sdkInstance._tracerProvider`. An issue can be opened to discuss the exposure
// of a public getter with the OpenTelemetry developers.
//
// `beforeExit`
//
// If set, Apostrophe will invoke it (await) before invoking process.exit.
// `beforeExit` may be an async function, will be awaited, and takes no arguments.
// `beforeExit` may be an async function, will be awaited, and takes no
// arguments.
//
// `pnpm`
// A boolean to force on or off the pnpm related build routines. If not set,
// an automated check will be performed to determine if pnpm is in use. We offer
// an option, because automated check is not 100% reliable. Monorepo tools are
// often hiding package management specifics (lock files, node_module structure, etc.)
// in a centralized store.
// often hiding package management specifics (lock files, node_module
// structure, etc.) in a centralized store.
//
// ## Awaiting the Apostrophe function
//
Expand Down Expand Up @@ -147,7 +148,8 @@ module.exports = async function(options) {
return null;
});
} else {
// continue as a worker operation, the pid should be recorded by the auto instrumentation
// continue as a worker operation, the pid should be recorded
// by the auto instrumentation
spanName += ':worker';
console.log(`Cluster worker ${process.pid} started`);
}
Expand Down Expand Up @@ -248,8 +250,9 @@ async function apostrophe(options, telemetry, rootSpan) {
}
};

// Signals to various (build related) places that we are running a pnpm installation.
// The relevant option, if set, has a higher precedence over the automated check.
// Signals to various (build related) places that we are running a pnpm
// installation. The relevant option, if set, has a higher precedence over
// the automated check.
self.isPnpm = options.pnpm ??
fs.existsSync(path.join(self.npmRootDir, 'pnpm-lock.yaml'));

Expand Down Expand Up @@ -320,17 +323,17 @@ async function apostrophe(options, telemetry, rootSpan) {
self.apos.schema.registerAllSchemas();
await self.apos.lock.withLock('@apostrophecms/migration:migrate', async () => {
await self.apos.migration.migrate(self.argv);
// Inserts the global doc in the default locale if it does not exist; same for other
// singleton piece types registered by other modules
// Inserts the global doc in the default locale if it does not exist;
// same for other singleton piece types registered by other modules
for (const apostropheModule of Object.values(self.modules)) {
if (self.instanceOf(apostropheModule, '@apostrophecms/piece-type') && apostropheModule.options.singletonAuto) {
await apostropheModule.insertIfMissing();
}
}
await self.apos.page.implementParkAllInDefaultLocale();
await self.apos.doc.replicate(); // emits beforeReplicate and afterReplicate events
// Replicate will have created the parked pages across locales if needed, but we may
// still need to reset parked properties
// Replicate will have created the parked pages across locales if needed,
// but we may still need to reset parked properties
await self.apos.page.implementParkAllInOtherLocales();
});
await self.emit('ready'); // formerly afterInit
Expand Down Expand Up @@ -625,8 +628,9 @@ async function apostrophe(options, telemetry, rootSpan) {
if (!target) {
continue;
}
// Add all the modules that want to be before this one to the target's beforeSelf.
// Do this recursively for every module from the beforeSelf array that has own `beforeSelf` members.
// Add all the modules that want to be before this one to the target's
// beforeSelf. Do this recursively for every module from the beforeSelf
// array that has own `beforeSelf` members.
addBeforeSelfRecursive(name, m.beforeSelf, target.beforeSelf);
}

Expand Down Expand Up @@ -670,7 +674,8 @@ async function apostrophe(options, telemetry, rootSpan) {
function modulesToBeInstantiated() {
return Object.keys(self.options.modules).filter(name => {
const improvement = self.synth.isImprovement(name);
return !(self.options.modules[name] && (improvement || self.options.modules[name].instantiate === false));
return !(self.options.modules[name] &&
(improvement || self.options.modules[name].instantiate === false));
});
}

Expand Down Expand Up @@ -712,7 +717,11 @@ async function apostrophe(options, telemetry, rootSpan) {
return;
}
const submodule = await self.root.import(path.resolve(self.localModules, name, 'index.js'));
if (submodule && submodule.options && submodule.options.ignoreUnusedFolderWarning) {
if (
submodule &&
submodule.options &&
submodule.options.ignoreUnusedFolderWarning
) {
return;
}
} catch (e) {
Expand Down Expand Up @@ -777,14 +786,22 @@ async function apostrophe(options, telemetry, rootSpan) {
if (apostropheModule.options.extends && ((typeof apostropheModule.options.extends) === 'string')) {
lint(`The module ${name} contains an "extends" option. This is probably a\nmistake. In Apostrophe "extend" is used to extend other modules.`);
}
if (apostropheModule.options.singletonWarningIfNot && (name !== apostropheModule.options.singletonWarningIfNot)) {
if (
apostropheModule.options.singletonWarningIfNot &&
(name !== apostropheModule.options.singletonWarningIfNot)
) {
lint(`The module ${name} extends ${apostropheModule.options.singletonWarningIfNot}, which is normally\na singleton (Apostrophe creates only one instance of it). Two competing\ninstances will lead to problems. If you are adding project-level code to it,\njust use modules/${apostropheModule.options.singletonWarningIfNot}/index.js and do not use "extend".\nIf you are improving it via an npm module, use "improve" rather than "extend".\nIf neither situation applies you should probably just make a new module that does\nnot extend anything.\n\nIf you are sure you know what you are doing, you can set the\nsingletonWarningIfNot: false option for this module.`);
}
if (name.match(/-widget$/) && (!extending(apostropheModule)) && (!apostropheModule.options.ignoreNoExtendWarning)) {
lint(`The module ${name} does not extend anything.\n\nA -widget module usually extends @apostrophecms/widget-type or another widget type.\nOr possibly you forgot to npm install something.\n\nIf you are sure you are doing the right thing, set the\nignoreNoExtendWarning option to true for this module.`);
} else if (name.match(/-page$/) && (name !== '@apostrophecms/page') && (!extending(apostropheModule)) && (!apostropheModule.options.ignoreNoExtendWarning)) {
lint(`The module ${name} does not extend anything.\n\nA -page module usually extends @apostrophecms/page-type or\n@apostrophecms/piece-page-type or another page type.\nOr possibly you forgot to npm install something.\n\nIf you are sure you are doing the right thing, set the\nignoreNoExtendWarning option to true for this module.`);
} else if ((!extending(apostropheModule)) && (!hasCode(name)) && (!isBundle(name)) && (!apostropheModule.options.ignoreNoCodeWarning)) {
} else if (
!extending(apostropheModule) &&
!hasCode(name) &&
!isBundle(name) &&
!apostropheModule.options.ignoreNoCodeWarning
) {
lint(`The module ${name} does not extend anything and does not have any code.\n\nThis usually means that you:\n\n1. Forgot to "extend" another module\n2. Configured a module that comes from npm without npm installing it\n3. Simply haven't written your "index.js" yet\n\nIf you really want a module with no code, set the ignoreNoCodeWarning option\nto true for this module.`);
}
}
Expand Down
39 changes: 23 additions & 16 deletions lib/moog-require.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,18 @@ module.exports = async function(options) {

if (options.nestedModuleSubdirs) {
if (!self._indexes) {
// Fetching a list of index.js files on the first call and then searching it each time for
// one that refers to the right type name shaves as much as 60 seconds off the startup
// time in a large project, compared to using the glob cache feature
// Fetching a list of index.js files on the first call and then
// searching it each time for one that refers to the right type name
// shaves as much as 60 seconds off the startup time in a large project,
// compared to using the glob cache feature
self._indexes = glob(self.options.localModules + '/**/index.js', { follow: true });
}
const matches = self._indexes.filter(function(index) {
// Double-check that we're not confusing "@apostrophecms/asset" with "asset" by
// making sure "type" is not preceded by an npm namespace folder. If type is itself namespaced
// this never comes up (because npm namespaces don't nest). The risk is that a legitimate
// project level module that happens to end with the same name as a namespaced module
// Double-check that we're not confusing "@apostrophecms/asset" with
// "asset" by making sure "type" is not preceded by an npm namespace
// folder. If type is itself namespaced this never comes up (because npm
// namespaces don't nest). The risk is that a legitimate project level
// module that happens to end with the same name as a namespaced module
// will be rejected as a duplicate when nestedModuleSubdirs is present
return index.endsWith('/' + type + '/index.js') && !index.match(new RegExp(`/@[^/]+/${regExpQuote(type)}/index\\.js$`));
});
Expand All @@ -78,7 +80,11 @@ module.exports = async function(options) {
projectLevelPath = matches[0] ? path.normalize(matches[0]) : projectLevelPath;
}
if (fs.existsSync(projectLevelPath)) {
const { default: defaultProjectLevelDefinition } = await importFresh(resolveFrom(path.dirname(self.root.filename), projectLevelPath));
const {
default: defaultProjectLevelDefinition
} = await importFresh(
resolveFrom(path.dirname(self.root.filename), projectLevelPath)
);
projectLevelDefinition = defaultProjectLevelDefinition;
if (Object.keys(projectLevelDefinition).length === 0) {
/* eslint-disable-next-line no-console */
Expand Down Expand Up @@ -159,15 +165,15 @@ module.exports = async function(options) {
if (npmDefinition) {
result = await superDefine(type, npmDefinition);
if (npmDefinition.improve) {
// Restore the name of the improving module as otherwise our asset chains have
// multiple references to my-foo which is ambiguous
// Restore the name of the improving module as otherwise our asset
// chains have multiple references to my-foo which is ambiguous
result.__meta.name = originalType;
}
}
result = await superDefine(type, definition);
if (npmDefinition && npmDefinition.improve) {
// Restore the name of the improving module as otherwise our asset chains have
// multiple references to my-foo which is ambiguous
// Restore the name of the improving module as otherwise our asset chains
// have multiple references to my-foo which is ambiguous
result.__meta.name = self.originalToMy(originalType);
}
// Mark "my" modules as such
Expand Down Expand Up @@ -256,7 +262,8 @@ module.exports = async function(options) {
return [];
}

// Ternary is required because glob expects at least 2 entries when using curly braces
// Ternary is required because glob expects at least 2 entries
// when using curly braces
const pattern = workspaces.length === 1 ? workspaces[0] : `{${workspaces.join(',')}}`;
const packagePath = path.resolve(folder, pattern, 'package.json');
const workspacePackages = glob(packagePath, { follow: true });
Expand All @@ -275,9 +282,9 @@ module.exports = async function(options) {

self.applyImprovementsBeforeProjectLevel = () => {
for (const [ name, definition ] of Object.entries(self.definitions)) {
// At this stage the complete definition of a type is a linked list of `extend`
// properties starting from what should be project level, unless there
// are improvements. Shuffle project level to be the first in the
// At this stage the complete definition of a type is a linked list of
// `extend` properties starting from what should be project level, unless
// there are improvements. Shuffle project level to be the first in the
// linked list
if (definition.__meta.name !== self.originalToMy(name)) {
let candidate = definition;
Expand Down
41 changes: 23 additions & 18 deletions lib/moog.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ module.exports = function(options) {
// Now we want to start from the base class and go down
steps.reverse();

// Actually just the apos object merging in, app.js merging was handled elsewhere
// Actually just the apos object merging in, app.js merging was handled
// elsewhere
Object.assign(options, _options || {});

self.options.sections = self.options.sections || [];
Expand Down Expand Up @@ -186,7 +187,8 @@ module.exports = function(options) {
if (!that[`${cascade}Groups`]) {
that[`${cascade}Groups`] = {};
}
// You can have access to options within a function, if you choose to provide one
// You can have access to options within a function, if you choose to
// provide one
const properties = ((typeof step[cascade]) === 'function') ? step[cascade](that, options) : step[cascade];
if (properties) {
const valid = [ 'add', 'remove', 'order', 'group' ];
Expand Down Expand Up @@ -235,7 +237,8 @@ module.exports = function(options) {
if (properties.group) {
const groups = klona(that[`${cascade}Groups`]);
for (const value of Object.values(properties.group)) {
// Handle `operations` alias of `fields`. Only one of them should be used.
// Handle `operations` alias of `fields`. Only one of them should
// be used.
if (Array.isArray(value.operations)) {
value.fields = value.operations;
}
Expand Down Expand Up @@ -279,9 +282,9 @@ module.exports = function(options) {
}
}

// This needs to be after the options and cascades are compiled so it can manipulate
// the result, yet we've already reordered the steps with the superclass first,
// so walk them backwards to implement beforeSuperClass
// This needs to be after the options and cascades are compiled so it can
// manipulate the result, yet we've already reordered the steps with the
// superclass first, so walk them backwards to implement beforeSuperClass
for (let i = (steps.length - 1); (i >= 0); i--) {
const step = steps[i];
if (step.beforeSuperClass) {
Expand All @@ -293,14 +296,15 @@ module.exports = function(options) {
// in other sections
build(null, 'methods');

// Unparsed sections, like `queries` and `extendQueries`. These are just captured
// in an object with the props from each level so the module can do something with
// them at runtime. Do it before init so that init can carry out queries
// Unparsed sections, like `queries` and `extendQueries`. These are just
// captured in an object with the props from each level so the module can do
// something with them at runtime. Do it before init so that init can carry
// out queries
(self.options.unparsedSections || []).forEach(section => capture(section));

// init is called BEFORE routes etc. are called so that the section functions
// for those things can benefit from methods, properties, etc. set by init
// when deciding what to return
// init is called BEFORE routes etc. are called so that the section
// functions for those things can benefit from methods, properties, etc. set
// by init when deciding what to return
for (const step of steps) {
if (step.init) {
await step.init(that, options);
Expand All @@ -312,9 +316,9 @@ module.exports = function(options) {

// afterAllSections is called last and has access to self.routes, etc.
// For project-level developers this is usually not important, but
// the core does call certain methods in the @apostrophecms/modules base class
// implementation of afterAllSections to actually add the routes and handlers
// to the system
// the core does call certain methods in the @apostrophecms/modules base
// class implementation of afterAllSections to actually add the routes and
// handlers to the system
for (const step of steps) {
if (step.afterAllSections) {
await step.afterAllSections(that, options);
Expand Down Expand Up @@ -419,9 +423,10 @@ module.exports = function(options) {

self.options.unparsedSections = self.options.unparsedSections || [];

// Unparsed sections, like `queries` and `extendQueries`. These are just captured
// in an object with the props from each level so the module can do something with
// them at runtime. Do it before init so that init can carry out queries
// Unparsed sections, like `queries` and `extendQueries`. These are just
// captured in an object with the props from each level so the module can do
// something with them at runtime. Do it before init so that init can carry
// out queries
(self.options.unparsedSections || []).forEach(section => capture(section));

return that;
Expand Down
7 changes: 4 additions & 3 deletions lib/opentelemetry.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ module.exports = function (options = {}) {
}

/**
* Start and return a new span. Optionally provide a parent span or allow the parent
* span to be auto-detected.
* Start and return a new span. Optionally provide a parent span or allow the
* parent span to be auto-detected.
* Use this when the current code block does the tracing and it doesn't expect
* more tracing to happen down the line.
*
Expand Down Expand Up @@ -82,7 +82,8 @@ module.exports = function (options = {}) {
* @returns {api.Span|any} the return value of the handler or the newly created span
* @example
* // Activate span, return some value
* const value = await self.apos.telemetry.startActiveSpan(spanName, async (span) => {
* const value = await self.apos.telemetry.startActiveSpan(spanName, async
* (span) => {
* // Use the span, do work, end span, return any value
* span.end();
* return value;
Expand Down
Loading