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

Node14 Complete upgrade #1034

Merged
merged 27 commits into from
Dec 17, 2021
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
bb6b925
Fix Node selection when using built in node (#912)
hackacad Nov 5, 2021
ff84b35
[Release] add axios dependency to UI package
kavilla Nov 9, 2021
48b372d
Add support for codeowners to repo (#935)
ryanbogan Nov 16, 2021
8740e2a
[LIC] Allows the simplified header for new files (#936)
ashwin-pc Nov 17, 2021
4133cac
[Git] update PR template (#937)
kavilla Nov 17, 2021
3d69c4f
Add release notes for Dashboards 1.2.0 (#944)
seanneumann Nov 17, 2021
9047044
Add versioned document support in OSD
zuochengding Nov 2, 2021
86c202a
[Branding] prevent logging when config not set (#941)
kavilla Nov 23, 2021
b8c5453
[Version] Increment to 2.0 (#973)
kavilla Nov 23, 2021
8c11eff
Add Lychee Link Checker into OSD (#938)
zuochengding Dec 8, 2021
3ddaecb
Fix Lychee Link Checker Error (#1011)
zuochengding Dec 9, 2021
2d44dab
[CI] Add tests to github workflow
kavilla Nov 3, 2021
74eb00e
Add bwc tests for osd with bundle (#871)
ananzh Dec 15, 2021
879cd33
Add more bwc tests for osd without bundles (#900)
ananzh Dec 15, 2021
382ebe0
Add bwc test data for osd without bundle (#927)
ananzh Dec 15, 2021
160a7fd
Add bwc test data for osd with bundle (#940)
ananzh Dec 15, 2021
f665da3
Add more bwc tests for osd with bundles (#901)
ananzh Dec 15, 2021
b8f276f
[Backwards Compatibility] restore URL forwarding from legacy app
kavilla Dec 12, 2021
baa50c1
[draft] Node.js upgrade from 10 to 14
Nov 8, 2021
941820a
Adds transformIgnorePattern for lmdb-store and dependencies
Dec 9, 2021
dce8b19
Removes lmdb-store from transformIgnorePatterns and fixes unit test j…
boktorbb Dec 10, 2021
48f3a69
[CI] Add tests to github workflow
kavilla Nov 3, 2021
0e2bf03
Skips flaky server metrics collector tests
Dec 13, 2021
883239a
Update node version in github workflow to 14
Dec 14, 2021
861ca16
Bumps node to 14.18.2 and uses caret range for @types/node
Dec 14, 2021
fc3bd65
Merge feature/node14
Dec 17, 2021
a7173de
Fix local merge issues
Dec 17, 2021
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
Prev Previous commit
Next Next commit
[LIC] Allows the simplified header for new files (#936)
* [LIC] Allows the simplified header for new files

Signed-off-by: Ashwin Pc <ashwinpc@amazon.com>

* Updates licence variable names

Signed-off-by: Ashwin Pc <ashwinpc@amazon.com>

Co-authored-by: Ashwin Pc <ashwinpc@amazon.com>
  • Loading branch information
ashwin-pc and ashwin-pc authored Nov 17, 2021

Verified

This commit was signed with the committer’s verified signature.
AgustinBettati Agustin Bettati
commit 8740e2a4368900dc916640299c55a18e0e4cdb6f
27 changes: 20 additions & 7 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -30,7 +30,20 @@
* GitHub history for details.
*/

const NEW_OSS_HEADER = `
/**
* For new files created by OpenSearch Contributers
*/
const OSD_HEADER = `
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
`;

/**
* For files that modify or use code with an exsting OSS header
*/
const OSS_HEADER = `
/*
* SPDX-License-Identifier: Apache-2.0
*
@@ -151,7 +164,7 @@ module.exports = {
'@osd/eslint/require-license-header': [
'error',
{
license: NEW_OSS_HEADER,
licenses: [OSD_HEADER, OSS_HEADER],
},
],
'@osd/eslint/disallow-license-headers': [
@@ -187,7 +200,7 @@ module.exports = {
'@osd/eslint/require-license-header': [
'error',
{
license: SAFER_LODASH_SET_LODASH_HEADER,
licenses: [SAFER_LODASH_SET_LODASH_HEADER],
},
],
'@osd/eslint/disallow-license-headers': [
@@ -209,14 +222,14 @@ module.exports = {
'@osd/eslint/require-license-header': [
'error',
{
license: SAFER_LODASH_SET_HEADER,
licenses: [SAFER_LODASH_SET_HEADER],
},
],
'@osd/eslint/disallow-license-headers': [
'error',
{
licenses: [
NEW_OSS_HEADER,
OSS_HEADER,
ELASTIC_LICENSE_HEADER,
APACHE_2_0_LICENSE_HEADER,
SAFER_LODASH_SET_LODASH_HEADER,
@@ -233,14 +246,14 @@ module.exports = {
'@osd/eslint/require-license-header': [
'error',
{
license: SAFER_LODASH_SET_DEFINITELYTYPED_HEADER,
licenses: [SAFER_LODASH_SET_DEFINITELYTYPED_HEADER],
},
],
'@osd/eslint/disallow-license-headers': [
'error',
{
licenses: [
NEW_OSS_HEADER,
OSS_HEADER,
ELASTIC_LICENSE_HEADER,
APACHE_2_0_LICENSE_HEADER,
SAFER_LODASH_SET_HEADER,
Original file line number Diff line number Diff line change
@@ -50,7 +50,7 @@ ruleTester.run('@osd/eslint/require-license-header', rule, {
console.log('foo')
`,

options: [{ license: '/* license */' }],
options: [{ licenses: ['/* license */'] }],
},
{
code: dedent`
@@ -59,7 +59,17 @@ ruleTester.run('@osd/eslint/require-license-header', rule, {
console.log('foo')
`,

options: [{ license: '// license' }],
options: [{ licenses: ['// license'] }],
},
// multiple valid licenses
{
code: dedent`
/* license 2 */

console.log('foo')
`,

options: [{ licenses: ['/* license 1 */', '/* license 2 */'] }],
},
],

@@ -73,7 +83,7 @@ ruleTester.run('@osd/eslint/require-license-header', rule, {
options: [],
errors: [
{
message: '"license" option is required',
message: '"licenses" option is required',
},
],
},
@@ -84,10 +94,10 @@ ruleTester.run('@osd/eslint/require-license-header', rule, {
console.log('foo')
`,

options: [{ license: '/* one *//* two */' }],
options: [{ licenses: ['/* one *//* two */'] }],
errors: [
{
message: '"license" option must only include a single comment',
message: '"licenses[0]" option must only include a single comment',
},
],
},
@@ -98,10 +108,10 @@ ruleTester.run('@osd/eslint/require-license-header', rule, {
console.log('foo')
`,

options: [{ license: `// one\n// two` }],
options: [{ licenses: [`// one\n// two`] }],
errors: [
{
message: '"license" option must only include a single comment',
message: '"licenses[0]" option must only include a single comment',
},
],
},
@@ -114,15 +124,17 @@ ruleTester.run('@osd/eslint/require-license-header', rule, {

options: [
{
license: dedent`
licenses: [
dedent`
/* license */
console.log('hello world');
`,
],
},
],
errors: [
{
message: '"license" option must only include a single comment',
message: '"licenses[0]" option must only include a single comment',
},
],
},
@@ -133,10 +145,10 @@ ruleTester.run('@osd/eslint/require-license-header', rule, {
console.log('foo')
`,

options: [{ license: `console.log('hello world');` }],
options: [{ licenses: [`console.log('hello world');`] }],
errors: [
{
message: '"license" option must only include a single comment',
message: '"licenses[0]" option must only include a single comment',
},
],
},
@@ -147,7 +159,7 @@ ruleTester.run('@osd/eslint/require-license-header', rule, {
console.log('foo')
`,

options: [{ license: '/* license */' }],
options: [{ licenses: ['/* license */'] }],
errors: [
{
message: 'File must start with a license header',
@@ -171,7 +183,7 @@ ruleTester.run('@osd/eslint/require-license-header', rule, {
console.log('foo')
`,

options: [{ license: '/* license */' }],
options: [{ licenses: ['/* license */'] }],
errors: [
{
message: 'License header must be at the very beginning of the file',
@@ -193,7 +205,7 @@ ruleTester.run('@osd/eslint/require-license-header', rule, {
console.log('foo')
`,

options: [{ license: '/* license */' }],
options: [{ licenses: ['/* license */'] }],
errors: [
{
message: 'License header must be at the very beginning of the file',
@@ -208,5 +220,53 @@ ruleTester.run('@osd/eslint/require-license-header', rule, {
console.log('foo')
`,
},

// atleast one of multiple licenses must be present
{
code: dedent`
/* not license */
/* also not license */
console.log('foo')
`,

options: [{ licenses: ['/* license 1 */', '/* license 2 */'] }],
errors: [
{
message: 'File must start with a license header',
},
],

output: dedent`
/* license 1 */

/* not license */
/* also not license */
console.log('foo')
`,
},

// atleast one of multiple licenses must be present at the top of the file
{
code: dedent`
/* not license */
/* license 2 */
console.log('foo')
`,

options: [{ licenses: ['/* license 1 */', '/* license 2 */'] }],
errors: [
{
message: 'License header must be at the very beginning of the file',
},
],

output: dedent`
/* license 2 */

/* not license */

console.log('foo')
`,
},
],
});
53 changes: 32 additions & 21 deletions packages/osd-eslint-plugin-eslint/rules/require_license_header.js
Original file line number Diff line number Diff line change
@@ -45,8 +45,11 @@ module.exports = {
{
type: 'object',
properties: {
license: {
type: 'string',
licenses: {
type: 'array',
items: {
type: 'string',
},
},
},
additionalProperties: false,
@@ -56,33 +59,38 @@ module.exports = {
create: (context) => {
return {
Program(program) {
const license = init(context, program, function () {
const licenses = init(context, program, function () {
const options = context.options[0] || {};
const license = options.license;
const licenses = options.licenses;

assert(!!license, '"license" option is required');
assert(!!licenses, '"licenses" option is required');

const parsed = babelEslint.parse(license);
assert(!parsed.body.length, '"license" option must only include a single comment');
assert(
parsed.comments.length === 1,
'"license" option must only include a single comment'
);
return licenses.map((license, i) => {
const parsed = babelEslint.parse(license);
assert(
!parsed.body.length,
`"licenses[${i}]" option must only include a single comment`
);
assert(
parsed.comments.length === 1,
`"licenses[${i}]" option must only include a single comment`
);

return {
source: license,
nodeValue: normalizeWhitespace(parsed.comments[0].value),
};
return {
source: license,
nodeValue: normalizeWhitespace(parsed.comments[0].value),
};
});
});

if (!license) {
return;
}
if (!licenses || !licenses.length) return;

const sourceCode = context.getSourceCode();
const comment = sourceCode
.getAllComments()
.find((node) => normalizeWhitespace(node.value) === license.nodeValue);
.find((node) =>
licenses.map((license) => license.nodeValue).includes(normalizeWhitespace(node.value))
);

// no licence comment
if (!comment) {
@@ -97,13 +105,16 @@ module.exports = {
return undefined;
}

return fixer.replaceTextRange([0, 0], license.source + '\n\n');
return fixer.replaceTextRange([0, 0], licenses[0].source + '\n\n');
},
});
return;
}

// ensure there is nothing before the comment
const currentLicense = licenses.find(
(license) => normalizeWhitespace(comment.value) === license.nodeValue
);
const sourceBeforeNode = sourceCode
.getText()
.slice(0, sourceCode.getIndexFromLoc(comment.loc.start));
@@ -121,7 +132,7 @@ module.exports = {
// if removing whitespace is not possible
return [
fixer.remove(comment),
fixer.replaceTextRange([0, 0], license.source + '\n\n'),
fixer.replaceTextRange([0, 0], currentLicense.source + '\n\n'),
];
},
});