Skip to content

Commit 90ee3f3

Browse files
authored
chore: lint using twilio-style (twilio#100)
1 parent b3af9cc commit 90ee3f3

40 files changed

+822
-738
lines changed

.eslintrc

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
11
{
2-
"extends": "oclif",
3-
"plugins": ["mocha"],
4-
"env": {
5-
"mocha": true
2+
"extends": [
3+
"twilio",
4+
"twilio-mocha"
5+
],
6+
"parserOptions": {
7+
"ecmaVersion": 2018
68
},
79
"rules": {
8-
"indent": ["error", 2],
9-
"linebreak-style": ["error", "unix"],
10-
"quotes": ["error", "single"],
11-
"semi": ["error", "always"],
12-
"object-curly-spacing": ["error", "always"],
13-
"comma-dangle": ["error", "never"],
14-
"mocha/no-exclusive-tests": "error",
15-
"node/no-extraneous-require": [
16-
"error",
17-
{
18-
"allowModules": ["lodash", "request", "q"]
19-
}
20-
]
10+
"global-require": "off",
11+
"prefer-named-capture-group": "off"
2112
}
22-
}
13+
}

package.json

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,29 @@
11
{
22
"name": "@twilio/cli-core",
3-
"description": "Core functionality for the twilio-cli",
43
"version": "5.8.0",
5-
"author": "Twilio @twilio",
4+
"description": "Core functionality for the twilio-cli",
5+
"keywords": [
6+
"twilio"
7+
],
8+
"homepage": "https://github.com/twilio/twilio-cli-core",
69
"bugs": "https://github.com/twilio/twilio-cli/issues",
10+
"repository": {
11+
"type": "git",
12+
"url": "https://github.com/twilio/twilio-cli-core.git"
13+
},
14+
"license": "MIT",
15+
"author": "Twilio @twilio",
16+
"main": "src/index.js",
17+
"files": [
18+
"/bin",
19+
"/src"
20+
],
21+
"scripts": {
22+
"lint": "eslint --ext js --ext jsx src/ test/",
23+
"lint:fix": "npm run lint -- --fix",
24+
"test": "nyc --check-coverage --lines 90 --reporter=html --reporter=text mocha --forbid-only \"test/**/*.test.js\"",
25+
"posttest": "eslint --ignore-path .gitignore . && npm audit --audit-level=moderate"
26+
},
727
"dependencies": {
828
"@oclif/command": "^1.7.0",
929
"@oclif/config": "^1.16.0",
@@ -20,41 +40,23 @@
2040
"tsv": "^0.2.0",
2141
"twilio": "^3.48.1"
2242
},
23-
"optionalDependencies": {
24-
"keytar": "^6.0.1"
25-
},
2643
"devDependencies": {
2744
"@oclif/test": "^1.2.6",
2845
"@twilio/cli-test": "^2.1.0",
2946
"chai": "^4.2.0",
30-
"eslint": "^7.3.1",
31-
"eslint-config-oclif": "^3.1.0",
32-
"eslint-plugin-mocha": "^7.0.1",
47+
"eslint": "^7.5.0",
48+
"eslint-config-twilio": "^1.28.0",
49+
"eslint-config-twilio-mocha": "^1.28.0",
3350
"mocha": "^8.0.1",
3451
"nock": "^13.0.2",
3552
"nyc": "^15.1.0",
3653
"sinon": "^9.0.2",
3754
"tmp": "^0.2.1"
3855
},
56+
"optionalDependencies": {
57+
"keytar": "^6.0.1"
58+
},
3959
"engines": {
4060
"node": ">=10.12.0"
41-
},
42-
"files": [
43-
"/bin",
44-
"/src"
45-
],
46-
"homepage": "https://github.com/twilio/twilio-cli-core",
47-
"keywords": [
48-
"twilio"
49-
],
50-
"license": "MIT",
51-
"main": "src/index.js",
52-
"repository": {
53-
"type": "git",
54-
"url": "https://github.com/twilio/twilio-cli-core.git"
55-
},
56-
"scripts": {
57-
"posttest": "eslint --ignore-path .gitignore . && npm audit --audit-level=moderate",
58-
"test": "nyc --check-coverage --lines 90 --reporter=html --reporter=text mocha --forbid-only \"test/**/*.test.js\""
5961
}
6062
}

src/base-commands/base-command.js

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
const { Command, flags } = require('@oclif/command');
1+
const { Command, flags: oclifFlags } = require('@oclif/command');
22
const { CLIError } = require('@oclif/errors');
3+
34
const pkg = require('../../package.json');
45
const MessageTemplates = require('../services/messaging/templates');
56
const { Config, ConfigData } = require('../services/config');
@@ -9,6 +10,7 @@ const { OutputFormats } = require('../services/output-formats');
910
const { getCommandPlugin, requireInstall } = require('../services/require-install');
1011
const { SecureStorage } = require('../services/secure-storage');
1112
const { instanceOf } = require('../services/javascript-utilities');
13+
1214
let inquirer; // We'll lazy-load this only when it's needed.
1315

1416
const DEFAULT_LOG_LEVEL = 'info';
@@ -40,7 +42,7 @@ class BaseCommand extends Command {
4042
this.logger = logger;
4143
this.logger.config.level = LoggingLevel[flags['cli-log-level'] || DEFAULT_LOG_LEVEL];
4244

43-
this.logger.debug('Config File: ' + this.configFile.filePath);
45+
this.logger.debug(`Config File: ${this.configFile.filePath}`);
4446

4547
// Replace oclif's output commands
4648
this.log = this.logger.info;
@@ -65,20 +67,31 @@ class BaseCommand extends Command {
6567
this.exit(error.exitCode || 1);
6668
} else {
6769
// System errors
68-
const plugin = getCommandPlugin(this);
69-
this.logger.error(MessageTemplates.unexpectedError({ url: this.getIssueUrl(plugin) }));
70+
let url = '';
71+
try {
72+
url = this.getIssueUrl(getCommandPlugin(this));
73+
} catch (e) {
74+
// No-op
75+
}
76+
77+
this.logger.error(MessageTemplates.unexpectedError({ url }));
7078
this.logger.debug(error.message);
7179
this.logger.debug(error.stack);
7280
this.exit(1);
7381
}
82+
83+
throw error;
7484
}
7585

7686
getIssueUrl(plugin) {
77-
const getPropertyUrl = value => value && (value.url || value);
78-
const getPackageUrl = pjson => getPropertyUrl(pjson.bugs) || getPropertyUrl(pjson.homepage) || getPropertyUrl(pjson.repository);
79-
80-
// If we found the plugin and an issue URL for it, use it. Otherwise
81-
// fallback to our own issue URL.
87+
const getPropertyUrl = (value) => value && (value.url || value);
88+
const getPackageUrl = (pjson) =>
89+
getPropertyUrl(pjson.bugs) || getPropertyUrl(pjson.homepage) || getPropertyUrl(pjson.repository);
90+
91+
/*
92+
* If we found the plugin and an issue URL for it, use it. Otherwise
93+
* fallback to our own issue URL.
94+
*/
8295
return (plugin && getPackageUrl(plugin.pjson)) || getPackageUrl(pkg);
8396
}
8497

@@ -105,16 +118,16 @@ class BaseCommand extends Command {
105118

106119
const limitedData = properties ? this.getLimitedData(dataArray, properties) : null;
107120

108-
process.stdout.write(this.outputProcessor(dataArray, limitedData || dataArray, options) + '\n');
121+
process.stdout.write(`${this.outputProcessor(dataArray, limitedData || dataArray, options)}\n`);
109122
}
110123

111124
getLimitedData(dataArray, properties) {
112125
const invalidPropertyNames = new Set();
113-
const propNames = properties.split(',').map(p => p.trim());
114-
const limitedData = dataArray.map(fullItem => {
126+
const propNames = properties.split(',').map((p) => p.trim());
127+
const limitedData = dataArray.map((fullItem) => {
115128
const limitedItem = {};
116129

117-
propNames.forEach(p => {
130+
propNames.forEach((p) => {
118131
let propValue = fullItem[p];
119132

120133
if (propValue === undefined) {
@@ -137,7 +150,7 @@ class BaseCommand extends Command {
137150

138151
if (invalidPropertyNames.size > 0) {
139152
const warn = this.logger.warn.bind(this.logger);
140-
invalidPropertyNames.forEach(p => {
153+
invalidPropertyNames.forEach((p) => {
141154
warn(`"${p}" is not a valid property name.`);
142155
});
143156
}
@@ -156,21 +169,21 @@ class BaseCommand extends Command {
156169
}
157170

158171
BaseCommand.flags = {
159-
'cli-log-level': flags.enum({
172+
'cli-log-level': oclifFlags.enum({
160173
char: 'l',
161174
helpLabel: '-l',
162175
default: DEFAULT_LOG_LEVEL,
163176
options: Object.keys(LoggingLevel),
164-
description: 'Level of logging messages.'
177+
description: 'Level of logging messages.',
165178
}),
166179

167-
'cli-output-format': flags.enum({
180+
'cli-output-format': oclifFlags.enum({
168181
char: 'o',
169182
helpLabel: '-o',
170183
default: DEFAULT_OUTPUT_FORMAT,
171184
options: Object.keys(OutputFormats),
172-
description: 'Format of command output.'
173-
})
185+
description: 'Format of command output.',
186+
}),
174187
};
175188

176189
module.exports = BaseCommand;

src/base-commands/twilio-client-command.js

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const { flags } = require('@oclif/command');
2+
23
const BaseCommand = require('./base-command');
34
const CliRequestClient = require('../services/cli-http-client');
45
const { TwilioApiClient, TwilioApiFlags } = require('../services/twilio-api');
@@ -27,18 +28,16 @@ class TwilioClientCommand extends BaseCommand {
2728

2829
const reportUnconfigured = (verb, message = '') => {
2930
const profileParam = this.flags.profile ? ` --profile "${this.flags.profile}"` : '';
30-
throw new TwilioCliError(
31-
`To ${verb} the profile, run:\n\n twilio profiles:create${profileParam}${message}`
32-
);
31+
throw new TwilioCliError(`To ${verb} the profile, run:\n\n twilio profiles:create${profileParam}${message}`);
3332
};
3433

3534
if (!this.currentProfile) {
3635
const profileName = this.flags.profile ? ` "${this.flags.profile}"` : '';
3736
this.logger.error(`Could not find profile${profileName}.`);
38-
reportUnconfigured('create', '\n\n' + HELP_ENVIRONMENT_VARIABLES);
37+
reportUnconfigured('create', `\n\n${HELP_ENVIRONMENT_VARIABLES}`);
3938
}
4039

41-
this.logger.debug('Using profile: ' + this.currentProfile.id);
40+
this.logger.debug(`Using profile: ${this.currentProfile.id}`);
4241

4342
if (!this.currentProfile.apiKey || !this.currentProfile.apiSecret) {
4443
const creds = await this.secureStorage.getCredentials(this.currentProfile.id);
@@ -54,11 +53,14 @@ class TwilioClientCommand extends BaseCommand {
5453
}
5554

5655
async catch(error) {
57-
// Append to the error message when catching API access denied errors with
58-
// profile-auth (i.e., standard API key auth).
56+
/*
57+
* Append to the error message when catching API access denied errors with
58+
* profile-auth (i.e., standard API key auth).
59+
*/
5960
if (instanceOf(error, TwilioCliError) && error.exitCode === ACCESS_DENIED_CODE) {
60-
if (!this.currentProfile.id.startsWith('${TWILIO')) { // Auth *not* using env vars.
61-
error.message += '\n\n' + ACCESS_DENIED;
61+
if (!this.currentProfile.id.startsWith('${TWILIO')) {
62+
// Auth *not* using env vars.
63+
error.message += `\n\n${ACCESS_DENIED}`;
6264
}
6365
}
6466

@@ -71,7 +73,7 @@ class TwilioClientCommand extends BaseCommand {
7173
}
7274

7375
let updatedProperties = null;
74-
Object.keys(this.constructor.PropertyFlags).forEach(propName => {
76+
Object.keys(this.constructor.PropertyFlags).forEach((propName) => {
7577
if (this.flags[propName] !== undefined) {
7678
updatedProperties = updatedProperties || {};
7779
const paramName = camelCase(propName);
@@ -85,7 +87,7 @@ class TwilioClientCommand extends BaseCommand {
8587
async updateResource(resource, resourceSid, updatedProperties) {
8688
const results = {
8789
sid: resourceSid,
88-
result: '?'
90+
result: '?',
8991
};
9092

9193
updatedProperties = updatedProperties || this.parseProperties();
@@ -128,38 +130,36 @@ class TwilioClientCommand extends BaseCommand {
128130
accountSid: this.flags[CliFlags.ACCOUNT_SID] || this.currentProfile.accountSid,
129131
edge: process.env.TWILIO_EDGE || this.userConfig.edge,
130132
region: this.currentProfile.region,
131-
httpClient: this.httpClient
133+
httpClient: this.httpClient,
132134
});
133135
}
134136
}
135137

136-
TwilioClientCommand.flags = Object.assign(
137-
{
138-
profile: flags.string({
139-
char: 'p',
140-
description: 'Shorthand identifier for your profile.'
141-
})
142-
},
143-
BaseCommand.flags
144-
);
138+
TwilioClientCommand.flags = {
139+
profile: flags.string({
140+
char: 'p',
141+
description: 'Shorthand identifier for your profile.',
142+
}),
143+
...BaseCommand.flags,
144+
};
145145

146146
TwilioClientCommand.accountSidFlag = {
147147
[CliFlags.ACCOUNT_SID]: flags.string({
148-
description: 'Access resources for the specified account.'
149-
})
148+
description: 'Access resources for the specified account.',
149+
}),
150150
};
151151

152152
TwilioClientCommand.limitFlags = {
153153
[CliFlags.LIMIT]: flags.string({
154154
description: `The maximum number of resources to return. Use '--${CliFlags.NO_LIMIT}' to disable.`,
155155
default: 50,
156-
exclusive: [CliFlags.NO_LIMIT]
156+
exclusive: [CliFlags.NO_LIMIT],
157157
}),
158158
[CliFlags.NO_LIMIT]: flags.boolean({
159159
default: false,
160160
hidden: true,
161-
exclusive: [CliFlags.LIMIT]
162-
})
161+
exclusive: [CliFlags.LIMIT],
162+
}),
163163
};
164164

165165
module.exports = TwilioClientCommand;

src/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module.exports = {
22
baseCommands: {
33
BaseCommand: require('./base-commands/base-command'),
4-
TwilioClientCommand: require('./base-commands/twilio-client-command')
4+
TwilioClientCommand: require('./base-commands/twilio-client-command'),
55
},
66
services: {
77
TwilioApi: require('./services/twilio-api'),
@@ -13,7 +13,7 @@ module.exports = {
1313
templating: require('./services/messaging/templating'),
1414
namingConventions: require('./services/naming-conventions'),
1515
outputFormats: require('./services/output-formats'),
16-
secureStorage: require('./services/secure-storage')
16+
secureStorage: require('./services/secure-storage'),
1717
},
18-
configureEnv: require('./services/env')
18+
configureEnv: require('./services/env'),
1919
};

0 commit comments

Comments
 (0)