Skip to content

Commit a3ed37a

Browse files
authored
build: configure ESLint to enforce stdlib package usage
PR-URL: #8232 Reviewed-by: Athan Reines <[email protected]>
1 parent 63af7d2 commit a3ed37a

File tree

1 file changed

+149
-1
lines changed

1 file changed

+149
-1
lines changed

etc/eslint/rules/style.js

Lines changed: 149 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1223,7 +1223,155 @@ rules[ 'no-restricted-syntax' ] = [ 'error',
12231223
'ImportDeclaration',
12241224
'ImportSpecifier',
12251225
'ImportDefaultSpecifier',
1226-
'ImportNamespaceSpecifier'
1226+
'ImportNamespaceSpecifier',
1227+
1228+
// Enforce stdlib package usage over built-in methods:
1229+
1230+
// String.prototype.endsWith
1231+
{
1232+
'selector': 'CallExpression[callee.property.name="endsWith"]',
1233+
'message': 'Use `@stdlib/string/ends-with` or `@stdlib/string/base/ends-with` instead of String.prototype.endsWith.'
1234+
},
1235+
1236+
// String.prototype.startsWith
1237+
{
1238+
'selector': 'CallExpression[callee.property.name="startsWith"]',
1239+
'message': 'Use `@stdlib/string/starts-with` or `@stdlib/string/base/starts-with` instead of String.prototype.startsWith.'
1240+
},
1241+
1242+
// String.prototype.toLowerCase
1243+
{
1244+
'selector': 'CallExpression[callee.property.name="toLowerCase"]',
1245+
'message': 'Use `@stdlib/string/lowercase` or `@stdlib/string/base/lowercase` instead of String.prototype.toLowerCase.'
1246+
},
1247+
1248+
// String.prototype.toUpperCase
1249+
{
1250+
'selector': 'CallExpression[callee.property.name="toUpperCase"]',
1251+
'message': 'Use `@stdlib/string/uppercase` or `@stdlib/string/base/uppercase` instead of String.prototype.toUpperCase.'
1252+
},
1253+
1254+
// String.prototype.trim
1255+
{
1256+
'selector': 'CallExpression[callee.property.name="trim"]',
1257+
'message': 'Use `@stdlib/string/trim` or `@stdlib/string/base/trim` instead of String.prototype.trim.'
1258+
},
1259+
1260+
// String.prototype.trimStart / trimLeft
1261+
{
1262+
'selector': 'CallExpression[callee.property.name="trimStart"]',
1263+
'message': 'Use `@stdlib/string/base/left-trim` instead of String.prototype.trimStart.'
1264+
},
1265+
{
1266+
'selector': 'CallExpression[callee.property.name="trimLeft"]',
1267+
'message': 'Use `@stdlib/string/base/left-trim` instead of String.prototype.trimLeft.'
1268+
},
1269+
1270+
// String.prototype.trimEnd / trimRight
1271+
{
1272+
'selector': 'CallExpression[callee.property.name="trimEnd"]',
1273+
'message': 'Use `@stdlib/string/base/right-trim` instead of String.prototype.trimEnd.'
1274+
},
1275+
{
1276+
'selector': 'CallExpression[callee.property.name="trimRight"]',
1277+
'message': 'Use `@stdlib/string/base/right-trim` instead of String.prototype.trimRight.'
1278+
},
1279+
1280+
// Object.keys
1281+
{
1282+
'selector': 'CallExpression[callee.object.name="Object"][callee.property.name="keys"]',
1283+
'message': 'Use `@stdlib/utils/keys` instead of Object.keys.'
1284+
},
1285+
1286+
// Object.values
1287+
{
1288+
'selector': 'CallExpression[callee.object.name="Object"][callee.property.name="values"]',
1289+
'message': 'Use `@stdlib/utils/values` instead of Object.values.'
1290+
},
1291+
1292+
// Object.entries
1293+
{
1294+
'selector': 'CallExpression[callee.object.name="Object"][callee.property.name="entries"]',
1295+
'message': 'Use `@stdlib/utils/entries` instead of Object.entries.'
1296+
},
1297+
1298+
// Object.defineProperty
1299+
{
1300+
'selector': 'CallExpression[callee.object.name="Object"][callee.property.name="defineProperty"]',
1301+
'message': 'Use `@stdlib/utils/define-property` instead of Object.defineProperty.'
1302+
},
1303+
1304+
// fs.readFile
1305+
{
1306+
'selector': 'CallExpression[callee.object.name="fs"][callee.property.name="readFile"]',
1307+
'message': 'Use `@stdlib/fs/read-file` instead of fs.readFile.'
1308+
},
1309+
{
1310+
'selector': 'CallExpression[callee.object.name="fs"][callee.property.name="readFileSync"]',
1311+
'message': 'Use `@stdlib/fs/read-file` instead of fs.readFileSync.'
1312+
},
1313+
1314+
// fs.writeFile
1315+
{
1316+
'selector': 'CallExpression[callee.object.name="fs"][callee.property.name="writeFile"]',
1317+
'message': 'Use `@stdlib/fs/write-file` instead of fs.writeFile.'
1318+
},
1319+
{
1320+
'selector': 'CallExpression[callee.object.name="fs"][callee.property.name="writeFileSync"]',
1321+
'message': 'Use `@stdlib/fs/write-file` instead of fs.writeFileSync.'
1322+
},
1323+
1324+
// fs.readdir
1325+
{
1326+
'selector': 'CallExpression[callee.object.name="fs"][callee.property.name="readdir"]',
1327+
'message': 'Use `@stdlib/fs/read-dir` instead of fs.readdir.'
1328+
},
1329+
{
1330+
'selector': 'CallExpression[callee.object.name="fs"][callee.property.name="readdirSync"]',
1331+
'message': 'Use `@stdlib/fs/read-dir` instead of fs.readdirSync.'
1332+
},
1333+
1334+
// fs.exists
1335+
{
1336+
'selector': 'CallExpression[callee.object.name="fs"][callee.property.name="exists"]',
1337+
'message': 'Use `@stdlib/fs/exists` instead of fs.exists.'
1338+
},
1339+
{
1340+
'selector': 'CallExpression[callee.object.name="fs"][callee.property.name="existsSync"]',
1341+
'message': 'Use `@stdlib/fs/exists` instead of fs.existsSync.'
1342+
},
1343+
1344+
// fs.unlink
1345+
{
1346+
'selector': 'CallExpression[callee.object.name="fs"][callee.property.name="unlink"]',
1347+
'message': 'Use `@stdlib/fs/unlink` instead of fs.unlink.'
1348+
},
1349+
{
1350+
'selector': 'CallExpression[callee.object.name="fs"][callee.property.name="unlinkSync"]',
1351+
'message': 'Use `@stdlib/fs/unlink` instead of fs.unlinkSync.'
1352+
},
1353+
1354+
// fs.rename
1355+
{
1356+
'selector': 'CallExpression[callee.object.name="fs"][callee.property.name="rename"]',
1357+
'message': 'Use `@stdlib/fs/rename` instead of fs.rename.'
1358+
},
1359+
{
1360+
'selector': 'CallExpression[callee.object.name="fs"][callee.property.name="renameSync"]',
1361+
'message': 'Use `@stdlib/fs/rename` instead of fs.renameSync.'
1362+
},
1363+
1364+
// path.dirname
1365+
{
1366+
'selector': 'CallExpression[callee.object.name="path"][callee.property.name="dirname"]',
1367+
'message': 'Use `@stdlib/utils/dirname` instead of path.dirname.'
1368+
},
1369+
1370+
// path.extname
1371+
{
1372+
'selector': 'CallExpression[callee.object.name="path"][callee.property.name="extname"]',
1373+
'message': 'Use `@stdlib/utils/extname` instead of path.extname.'
1374+
}
12271375
];
12281376

12291377
/**

0 commit comments

Comments
 (0)