@@ -19,7 +19,7 @@ import {
1919 buildMonthlyIssuesMetricsWorkflow ,
2020 buildAutoApproveWorkflow ,
2121 buildOrtToolkitWorkflow ,
22- //runSemGrepWorkflow,
22+ // runSemGrepWorkflow,
2323 runBanditWorkflow ,
2424 runCommitLintWorkflow ,
2525 buildCodeGenerationWorkflow ,
@@ -71,6 +71,7 @@ const project = new awscdk.AwsCdkConstructLibrary({
7171 'aws-sdk-mock' ,
7272 '@aws-cdk/assert' ,
7373 `@aws-cdk/integ-tests-alpha@${ CDK_VERSION } -alpha.0` ,
74+ '@cdklabs/eslint-plugin' ,
7475 ] ,
7576 deps : [ 'cdk-nag' ] ,
7677 bundledDeps : [ 'deepmerge' , `@aws-cdk/aws-lambda-python-alpha@${ CDK_VERSION } -alpha.0` ] ,
@@ -93,7 +94,7 @@ const project = new awscdk.AwsCdkConstructLibrary({
9394 packageId : camelCaseIt ( PUBLICATION_NAMESPACE ) + '.' + camelCaseIt ( PROJECT_NAME ) ,
9495 } ,
9596
96- //TODO: JumpStartModel.java is over 64K skipping building Java distribution until resolved.
97+ // TODO: JumpStartModel.java is over 64K skipping building Java distribution until resolved.
9798 // publishToMaven: {
9899 // javaPackage: `io.github.${PUBLICATION_NAMESPACE.replace(/-/g, '_')}.${PROJECT_NAME.replace(/-/g, '_')}`,
99100 // mavenGroupId: `io.github.${PUBLICATION_NAMESPACE}`,
@@ -155,7 +156,7 @@ buildMeritBadgerWorkflow(project);
155156buildMonthlyIssuesMetricsWorkflow ( project ) ;
156157buildAutoApproveWorkflow ( project ) ;
157158buildOrtToolkitWorkflow ( project ) ;
158- //runSemGrepWorkflow(project);
159+ // runSemGrepWorkflow(project);
159160runBanditWorkflow ( project ) ;
160161runCommitLintWorkflow ( project ) ;
161162buildCodeGenerationWorkflow ( project ) ;
@@ -331,14 +332,119 @@ project.npmignore?.addPatterns(
331332 '.husky' ,
332333) ;
333334
334- // Add License header automatically
335- project . eslint ?. addPlugins ( 'license-header' ) ;
335+ project . eslint ?. addPlugins ( 'license-header' , '@cdklabs/eslint-plugin' ) ;
336336project . eslint ?. addRules ( {
337337 'license-header/header' : [ 'error' , 'header.js' ] ,
338- } ) ;
338+ '@cdklabs/no-core-construct' : [ 'error' ] ,
339+ '@cdklabs/invalid-cfn-imports' : [ 'error' ] ,
340+ '@cdklabs/no-literal-partition' : [ 'error' ] ,
341+ '@cdklabs/no-invalid-path' : [ 'error' ] ,
342+ '@cdklabs/promiseall-no-unbounded-parallelism' : [ 'error' ] ,
343+
344+ // Error handling
345+ 'no-throw-literal' : [ 'error' ] ,
346+
347+ '@stylistic/indent' : [ 'error' , 2 ] ,
348+
349+ // Style
350+ 'quotes' : [ 'error' , 'single' , { avoidEscape : true } ] ,
351+ '@stylistic/member-delimiter-style' : [ 'error' ] , // require semicolon delimiter
352+ '@stylistic/comma-dangle' : [ 'error' , 'always-multiline' ] , // ensures clean diffs, see https://medium.com/@nikgraf/why-you-should-enforce-dangling-commas-for-multiline-statements-d034c98e36f8
353+ '@stylistic/no-extra-semi' : [ 'error' ] , // no extra semicolons
354+ 'comma-spacing' : [ 'error' , { before : false , after : true } ] , // space after, no space before
355+ 'no-multi-spaces' : [ 'error' , { ignoreEOLComments : false } ] , // no multi spaces
356+ 'array-bracket-spacing' : [ 'error' , 'never' ] , // [1, 2, 3]
357+ 'array-bracket-newline' : [ 'error' , 'consistent' ] , // enforce consistent line breaks between brackets
358+ 'object-curly-spacing' : [ 'error' , 'always' ] , // { key: 'value' }
359+ 'object-curly-newline' : [ 'error' , { multiline : true , consistent : true } ] , // enforce consistent line breaks between braces
360+ 'object-property-newline' : [ 'error' , { allowAllPropertiesOnSameLine : true } ] , // enforce "same line" or "multiple line" on object properties
361+ 'keyword-spacing' : [ 'error' ] , // require a space before & after keywords
362+ 'brace-style' : [ 'error' , '1tbs' , { allowSingleLine : true } ] , // enforce one true brace style
363+ 'space-before-blocks' : 'error' , // require space before blocks
364+ 'curly' : [ 'error' , 'multi-line' , 'consistent' ] , // require curly braces for multiline control statements
365+ 'eol-last' : [ 'error' , 'always' ] , // require a newline a the end of files
366+ '@stylistic/spaced-comment' : [ 'error' , 'always' , { exceptions : [ '/' , '*' ] , markers : [ '/' ] } ] , // require a whitespace at the beginninng of each comment
367+ '@stylistic/padded-blocks' : [ 'error' , { classes : 'never' , blocks : 'never' , switches : 'never' } ] ,
368+ // Require all imported libraries actually resolve (!!required for import/no-extraneous-dependencies to work!!)
369+ 'import/no-unresolved' : [ 'error' ] ,
370+ // Require an ordering on all imports
371+ 'import/order' : [ 'error' , {
372+ groups : [ 'builtin' , 'external' ] ,
373+ alphabetize : { order : 'asc' , caseInsensitive : true } ,
374+ } ] ,
375+ // Cannot import from the same module twice
376+ 'no-duplicate-imports' : [ 'error' ] ,
377+
378+ // Cannot shadow names
379+ 'no-shadow' : [ 'off' ] ,
380+ // Required spacing in property declarations (copied from TSLint, defaults are good)
381+ 'key-spacing' : [ 'error' ] ,
382+
383+ // Require semicolons
384+ 'semi' : [ 'error' , 'always' ] ,
385+
386+ // Don't unnecessarily quote properties
387+ 'quote-props' : [ 'error' , 'consistent-as-needed' ] ,
388+
389+ // No multiple empty lines
390+ 'no-multiple-empty-lines' : [ 'error' , { max : 1 } ] ,
391+ // Max line lengths
392+ 'max-len' : [ 'error' , {
393+ code : 150 ,
394+ ignoreUrls : true , // Most common reason to disable it
395+ ignoreStrings : true , // These are not fantastic but necessary for error messages
396+ ignoreTemplateLiterals : true ,
397+ ignoreComments : true ,
398+ ignoreRegExpLiterals : true ,
399+ } ] ,
400+ // One of the easiest mistakes to make
401+ '@typescript-eslint/no-floating-promises' : [ 'error' ] ,
402+
403+ // Make sure that inside try/catch blocks, promises are 'return await'ed
404+ // (must disable the base rule as it can report incorrect errors)
405+ 'no-return-await' : 'off' ,
406+ '@typescript-eslint/return-await' : 'error' ,
407+ // Don't leave log statements littering the premises!
408+ 'no-console' : [ 'error' ] ,
339409
340- // https://eslint.style/rules/js/space-infix-ops
341- project . eslint ?. addRules ( { 'space-infix-ops' : [ 'error' , { int32Hint : false } ] } ) ;
410+ // Useless diff results
411+ 'no-trailing-spaces' : [ 'error' ] ,
412+
413+ // Must use foo.bar instead of foo['bar'] if possible
414+ 'dot-notation' : [ 'error' ] ,
415+ // Are you sure | is not a typo for || ?
416+ 'no-bitwise' : [ 'error' ] ,
417+ // No more md5, will break in FIPS environments
418+ 'no-restricted-syntax' : [
419+ 'error' ,
420+ {
421+ // Both qualified and unqualified calls
422+ selector : "CallExpression:matches([callee.name='createHash'], [callee.property.name='createHash']) Literal[value='md5']" ,
423+ message : 'Use the md5hash() function from the core library if you want md5' ,
424+ } ,
425+ ] ,
426+ // Member ordering
427+ '@typescript-eslint/member-ordering' : [ 'error' , {
428+ default : [
429+ 'public-static-field' ,
430+ 'public-static-method' ,
431+ 'protected-static-field' ,
432+ 'protected-static-method' ,
433+ 'private-static-field' ,
434+ 'private-static-method' ,
435+
436+ 'field' ,
437+
438+ // Constructors
439+ 'constructor' , // = ["public-constructor", "protected-constructor", "private-constructor"]
440+
441+ // Methods
442+ 'method' ,
443+ ] ,
444+ } ] ,
445+ // Too easy to make mistakes
446+ '@typescript-eslint/unbound-method' : 'error' ,
447+ } ) ;
342448
343449const packageJson = project . tryFindObjectFile ( 'package.json' ) ;
344450packageJson ?. patch ( JsonPatch . add ( '/scripts/prepare' , 'husky install' ) ) ; // yarn 1
0 commit comments