Skip to content

Commit 009caa9

Browse files
feat: introduce ESLint flat configuration and update related dependencies (#24)
* feat: introduce ESLint flat configuration and update related dependencies for analytics samples * test: upgrade eslint * remove jsdoc rules from eslint config, remove old config files, upgrade to node 20 * linting fixes * add file paths to lint and fix scripts * update scripts
1 parent bc08e82 commit 009caa9

59 files changed

Lines changed: 465 additions & 390 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

google-analytics-admin/.eslintrc.json

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import {defineConfig} from 'eslint/config';
2+
import globals from 'globals';
3+
import path from 'node:path';
4+
import {fileURLToPath} from 'node:url';
5+
import js from '@eslint/js';
6+
import {FlatCompat} from '@eslint/eslintrc';
7+
8+
const __filename = fileURLToPath(import.meta.url);
9+
const __dirname = path.dirname(__filename);
10+
const compat = new FlatCompat({
11+
baseDirectory: __dirname,
12+
recommendedConfig: js.configs.recommended,
13+
allConfig: js.configs.all,
14+
});
15+
16+
const googleConfig = compat.extends('google');
17+
for (const config of googleConfig) {
18+
if (config.rules) {
19+
delete config.rules['valid-jsdoc'];
20+
delete config.rules['require-jsdoc'];
21+
}
22+
}
23+
24+
export default defineConfig([
25+
...googleConfig,
26+
{
27+
files: ['*.js'],
28+
languageOptions: {
29+
globals: {
30+
...globals.browser,
31+
...globals.commonjs,
32+
},
33+
34+
ecmaVersion: 'latest',
35+
sourceType: 'script',
36+
},
37+
38+
rules: {},
39+
},
40+
]);

google-analytics-admin/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"license": "Apache-2.0",
55
"author": "Google LLC",
66
"engines": {
7-
"node": ">=18.0.0"
7+
"node": ">=20.0.0"
88
},
99
"files": [
1010
"*.js"
@@ -25,10 +25,13 @@
2525
"url": "^0.11.0"
2626
},
2727
"devDependencies": {
28+
"@eslint/eslintrc": "^3.3.3",
29+
"@eslint/js": "^9.39.2",
2830
"c8": "^10.0.0",
2931
"chai": "^4.2.0",
30-
"eslint": "^8.53.0",
32+
"eslint": "^10.0.0",
3133
"eslint-config-google": "^0.14.0",
34+
"globals": "^17.3.0",
3235
"mocha": "^11.0.0"
3336
}
3437
}

google-analytics-admin/quickstart.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function main() {
5858
// [END analytics_admin_quickstart]
5959
}
6060

61-
process.on('unhandledRejection', err => {
61+
process.on('unhandledRejection', (err) => {
6262
console.error(err.message);
6363
process.exitCode = 1;
6464
});

google-analytics-data/.eslintrc.json

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import {defineConfig} from 'eslint/config';
2+
import globals from 'globals';
3+
import path from 'node:path';
4+
import {fileURLToPath} from 'node:url';
5+
import js from '@eslint/js';
6+
import {FlatCompat} from '@eslint/eslintrc';
7+
8+
const __filename = fileURLToPath(import.meta.url);
9+
const __dirname = path.dirname(__filename);
10+
const compat = new FlatCompat({
11+
baseDirectory: __dirname,
12+
recommendedConfig: js.configs.recommended,
13+
allConfig: js.configs.all,
14+
});
15+
16+
const googleConfig = compat.extends('google');
17+
for (const config of googleConfig) {
18+
if (config.rules) {
19+
delete config.rules['valid-jsdoc'];
20+
delete config.rules['require-jsdoc'];
21+
}
22+
}
23+
24+
export default defineConfig([
25+
...googleConfig,
26+
{
27+
files: ['*.js', 'test/*.js'],
28+
languageOptions: {
29+
globals: {
30+
...globals.browser,
31+
...globals.commonjs,
32+
},
33+
34+
ecmaVersion: 'latest',
35+
sourceType: 'script',
36+
},
37+
38+
rules: {},
39+
},
40+
]);

google-analytics-data/get_common_metadata.js

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,19 @@
1414

1515
'use strict';
1616

17-
/** Google Analytics Data API sample application retrieving dimension and metrics
18-
metadata.
19-
20-
See https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/getMetadata
21-
for more information.
22-
23-
Before you start the application, please review the comments starting with
24-
"TODO(developer)" and update the code to use correct values.
25-
26-
Usage:
27-
npm install
28-
node getCommonMetadata.js
17+
/**
18+
* Google Analytics Data API sample application retrieving dimension and metrics
19+
* metadata.
20+
*
21+
* See https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/getMetadata
22+
* for more information.
23+
*
24+
* Before you start the application, please review the comments starting with
25+
* "TODO(developer)" and update the code to use correct values.
26+
*
27+
* Usage:
28+
* npm install
29+
* node getCommonMetadata.js
2930
*/
3031

3132
function main(propertyId = 'YOUR-GA4-PROPERTY-ID') {
@@ -43,13 +44,15 @@ function main(propertyId = 'YOUR-GA4-PROPERTY-ID') {
4344
// needs to be created once, and can be reused for multiple requests.
4445
const analyticsDataClient = new BetaAnalyticsDataClient();
4546

46-
// Retrieves dimensions and metrics available for all Google Analytics 4 properties.
47+
// Retrieves dimensions and metrics available for all Google Analytics 4
48+
// properties.
4749
async function getCommonMetadata() {
4850
const [response] = await analyticsDataClient.getMetadata({
4951
name: `properties/${propertyId}/metadata`,
5052
});
5153
console.log(
52-
'Dimensions and metrics available for all Google Analytics 4 properties:'
54+
'Dimensions and metrics available for all ' +
55+
'Google Analytics 4 properties:',
5356
);
5457
printGetMetadataResponse(response);
5558
}
@@ -58,11 +61,12 @@ function main(propertyId = 'YOUR-GA4-PROPERTY-ID') {
5861

5962
// Prints results of the getMetadata call.
6063
function printGetMetadataResponse(response) {
61-
//[START analyticsdata_print_get_metadata_response]
62-
response.dimensions.forEach(dimension => {
64+
// [START analyticsdata_print_get_metadata_response]
65+
response.dimensions.forEach((dimension) => {
6366
console.log('DIMENSION');
6467
console.log(
65-
`${dimension.apiName} (${dimension.uiName}): ${dimension.description}`
68+
`${dimension.apiName} (${dimension.uiName}): ` +
69+
`${dimension.description}`,
6670
);
6771
console.log(`custom definition: ${dimension.customDefinition}`);
6872
if (
@@ -74,10 +78,10 @@ function main(propertyId = 'YOUR-GA4-PROPERTY-ID') {
7478
console.log();
7579
});
7680

77-
response.metrics.forEach(metric => {
81+
response.metrics.forEach((metric) => {
7882
console.log('METRIC');
7983
console.log(
80-
`${metric.apiName} (${metric.uiName}): ${metric.description}`
84+
`${metric.apiName} (${metric.uiName}): ${metric.description}`,
8185
);
8286
console.log(`custom definition: ${metric.customDefinition}`);
8387
if (metric.expression) {
@@ -94,7 +98,7 @@ function main(propertyId = 'YOUR-GA4-PROPERTY-ID') {
9498
// [END analyticsdata_get_common_metadata]
9599
}
96100

97-
process.on('unhandledRejection', err => {
101+
process.on('unhandledRejection', (err) => {
98102
console.error(err.message);
99103
process.exitCode = 1;
100104
});

google-analytics-data/get_metadata_by_property_id.js

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,19 @@
1414

1515
'use strict';
1616

17-
/** Google Analytics Data API sample application retrieving dimension and metrics
18-
metadata.
19-
20-
See https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/getMetadata
21-
for more information.
22-
23-
Before you start the application, please review the comments starting with
24-
"TODO(developer)" and update the code to use correct values.
25-
26-
Usage:
27-
npm install
28-
node getMetadataByPropertyId.js
17+
/**
18+
* Google Analytics Data API sample application retrieving dimension and metrics
19+
* metadata.
20+
*
21+
* See https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/getMetadata
22+
* for more information.
23+
*
24+
* Before you start the application, please review the comments starting with
25+
* "TODO(developer)" and update the code to use correct values.
26+
*
27+
* Usage:
28+
* npm install
29+
* node getMetadataByPropertyId.js
2930
*/
3031

3132
function main(propertyId = 'YOUR-GA4-PROPERTY-ID') {
@@ -49,7 +50,8 @@ function main(propertyId = 'YOUR-GA4-PROPERTY-ID') {
4950
name: `properties/${propertyId}/metadata`,
5051
});
5152
console.log(
52-
`Dimensions and metrics available for a Google Analytics 4 property ${propertyId} (including custom fields):`
53+
'Dimensions and metrics available for a Google Analytics 4 ' +
54+
`property ${propertyId} (including custom fields):`,
5355
);
5456
printGetMetadataResponse(response);
5557
}
@@ -58,11 +60,12 @@ function main(propertyId = 'YOUR-GA4-PROPERTY-ID') {
5860

5961
// Prints results of the getMetadata call.
6062
function printGetMetadataResponse(response) {
61-
//[START analyticsdata_print_get_metadata_response]
62-
response.dimensions.forEach(dimension => {
63+
// [START analyticsdata_print_get_metadata_response]
64+
response.dimensions.forEach((dimension) => {
6365
console.log('DIMENSION');
6466
console.log(
65-
`${dimension.apiName} (${dimension.uiName}): ${dimension.description}`
67+
`${dimension.apiName} (${dimension.uiName}): ` +
68+
`${dimension.description}`,
6669
);
6770
console.log(`custom definition: ${dimension.customDefinition}`);
6871
if (
@@ -74,10 +77,10 @@ function main(propertyId = 'YOUR-GA4-PROPERTY-ID') {
7477
console.log();
7578
});
7679

77-
response.metrics.forEach(metric => {
80+
response.metrics.forEach((metric) => {
7881
console.log('METRIC');
7982
console.log(
80-
`${metric.apiName} (${metric.uiName}): ${metric.description}`
83+
`${metric.apiName} (${metric.uiName}): ${metric.description}`,
8184
);
8285
console.log(`custom definition: ${metric.customDefinition}`);
8386
if (metric.expression) {
@@ -94,7 +97,7 @@ function main(propertyId = 'YOUR-GA4-PROPERTY-ID') {
9497
// [END analyticsdata_get_metadata_by_property_id]
9598
}
9699

97-
process.on('unhandledRejection', err => {
100+
process.on('unhandledRejection', (err) => {
98101
console.error(err.message);
99102
process.exitCode = 1;
100103
});

google-analytics-data/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"license": "Apache-2.0",
55
"author": "Google LLC",
66
"engines": {
7-
"node": ">=18.0.0"
7+
"node": ">=20.0.0"
88
},
99
"files": [
1010
"*.js"
@@ -25,10 +25,13 @@
2525
"url": "^0.11.0"
2626
},
2727
"devDependencies": {
28+
"@eslint/eslintrc": "^3.3.3",
29+
"@eslint/js": "^9.39.2",
2830
"c8": "^10.0.0",
2931
"chai": "^4.2.0",
30-
"eslint": "^8.53.0",
32+
"eslint": "^10.0.0",
3133
"eslint-config-google": "^0.14.0",
34+
"globals": "^17.3.0",
3235
"mocha": "^11.0.0"
3336
}
3437
}

google-analytics-data/quickstart_json_credentials.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ function main(propertyId = 'YOUR-GA4-PROPERTY-ID', credentialsJsonPath = '') {
7878
// [END analyticsdata_json_credentials_run_report]
7979

8080
console.log('Report result:');
81-
response.rows.forEach(row => {
81+
response.rows.forEach((row) => {
8282
console.log(row.dimensionValues[0], row.metricValues[0]);
8383
});
8484
}
@@ -87,7 +87,7 @@ function main(propertyId = 'YOUR-GA4-PROPERTY-ID', credentialsJsonPath = '') {
8787
// [END analyticsdata_json_credentials_quickstart]
8888
}
8989

90-
process.on('unhandledRejection', err => {
90+
process.on('unhandledRejection', (err) => {
9191
console.error(err.message);
9292
process.exitCode = 1;
9393
});

0 commit comments

Comments
 (0)