Skip to content
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

Replace deprecated context#getSourceCode() for new context#sourceCode #13

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -42,7 +42,7 @@ module.exports = ruleComposer.joinReports([
semiRule,
context => ({
ClassProperty(node) {
if (context.getSourceCode().getLastToken(node).value !== ';') {
if (context.sourceCode.getLastToken(node).value !== ';') {
context.report({ node, message: 'Missing semicolon.' })
}
}
Expand Down
67 changes: 32 additions & 35 deletions lib/rule-composer.js
@@ -1,5 +1,3 @@
'use strict';

/**
* Translates a multi-argument context.report() call into a single object argument call
* @param {...*} arguments A list of arguments passed to `context.report`
Expand Down Expand Up @@ -47,7 +45,6 @@ function normalizeReportLoc(descriptor) {
return descriptor.node.loc;
}


/**
* Interpolates data placeholders in report messages
* @param {MessageDescriptor} descriptor The report message descriptor.
Expand Down Expand Up @@ -115,7 +112,7 @@ function getRuleCreateFunc(rule) {
}

function removeMessageIfMessageIdPresent(reportDescriptor) {
const newDescriptor = Object.assign({}, reportDescriptor);
const newDescriptor = { ...reportDescriptor };

if (typeof reportDescriptor.messageId === 'string' && typeof reportDescriptor.message === 'string') {
delete newDescriptor.message;
Expand All @@ -129,7 +126,7 @@ module.exports = Object.freeze({
return Object.freeze({
create(context) {
const filename = context.getFilename();
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;
const settings = context.settings;
const options = context.options;
return getRuleCreateFunc(rule)(
Expand All @@ -148,9 +145,9 @@ module.exports = Object.freeze({
}
},
},
}
)
)
},
),
),
);
},
schema: rule.schema,
Expand All @@ -161,7 +158,7 @@ module.exports = Object.freeze({
return Object.freeze({
create(context) {
const filename = context.getFilename();
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;
const settings = context.settings;
const options = context.options;
return getRuleCreateFunc(rule)(
Expand All @@ -178,15 +175,15 @@ module.exports = Object.freeze({
getReportNormalizer(rule).apply(null, arguments),
{
sourceCode, settings, options, filename,
}
)
)
},
),
),
);
},
},
}
)
)
},
),
),
);
},
schema: rule.schema,
Expand All @@ -197,32 +194,32 @@ module.exports = Object.freeze({
return Object.freeze({
create(context) {
return rules
.map(rule => getRuleCreateFunc(rule)(context))
.map((rule) => getRuleCreateFunc(rule)(context))
.reduce(
(allListeners, ruleListeners) =>
Object.keys(ruleListeners).reduce(
(combinedListeners, key) => {
const currentListener = combinedListeners[key];
const ruleListener = ruleListeners[key];
if (currentListener) {
return Object.assign({}, combinedListeners, {
[key]() {
currentListener.apply(null, arguments);
ruleListener.apply(null, arguments);
},
});
}
return Object.assign({}, combinedListeners, { [key]: ruleListener });
},
allListeners
),
Object.create(null)
(allListeners, ruleListeners) => Object.keys(ruleListeners).reduce(
(combinedListeners, key) => {
const currentListener = combinedListeners[key];
const ruleListener = ruleListeners[key];
if (currentListener) {
return {
...combinedListeners,
[key]() {
currentListener.apply(null, arguments);
ruleListener.apply(null, arguments);
},
};
}
return { ...combinedListeners, [key]: ruleListener };
},
allListeners,
),
Object.create(null),
);
},
meta: Object.freeze({
messages: Object.assign.apply(
null,
[Object.create(null)].concat(rules.map(getMessageIds))
[Object.create(null)].concat(rules.map(getMessageIds)),
),
fixable: 'code',
}),
Expand Down