Skip to content

Commit

Permalink
keep comments
Browse files Browse the repository at this point in the history
  • Loading branch information
dangowans committed Oct 31, 2024
1 parent 048ed86 commit b4407f3
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 3 deletions.
6 changes: 6 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// eslint-disable-next-line @eslint-community/eslint-comments/disable-enable-pair
/* eslint-disable @cspell/spellchecker, @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access */
import eslintCspell from '@cspell/eslint-plugin/recommended';
import eslint from '@eslint/js';
import eslintPluginEslintComments from '@eslint-community/eslint-plugin-eslint-comments/configs';
Expand All @@ -9,6 +11,7 @@ import * as eslintPluginRegexp from 'eslint-plugin-regexp';
import eslintPluginSecurity from 'eslint-plugin-security';
import eslintPluginSonarJs from 'eslint-plugin-sonarjs';
import eslintPluginUnicorn from 'eslint-plugin-unicorn';
// import * as eslintPluginWoke from 'eslint-plugin-woke'
import * as eslintPluginWriteGoodComments from 'eslint-plugin-write-good-comments';
import tseslint from 'typescript-eslint';
import cspellFlagWords from './wordLists/cspell.flagWords.js';
Expand All @@ -27,6 +30,7 @@ export const config = tseslint.config(eslint.configs.recommended, ...tseslint.co
},
plugins: {
'no-secrets': eslintPluginNoSecrets,
// woke: eslintPluginWoke,
'write-good-comments': eslintPluginWriteGoodComments
},
rules: {
Expand Down Expand Up @@ -73,6 +77,7 @@ export const config = tseslint.config(eslint.configs.recommended, ...tseslint.co
'n/no-missing-import': 'off',
'no-extra-semi': 'off',
'no-secrets/no-secrets': 'error',
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
'sonarjs/cognitive-complexity': ['warn', 20],
'sonarjs/no-duplicate-string': 'warn',
'sort-imports': [
Expand Down Expand Up @@ -115,6 +120,7 @@ export const config = tseslint.config(eslint.configs.recommended, ...tseslint.co
}
}
],
// 'woke/all': 'error',
'write-good-comments/write-good-comments': [
'warn',
{
Expand Down
9 changes: 9 additions & 0 deletions samples/jsdoc.sample.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
export declare function exportedNoJsDocs(): boolean;
export declare const one = 1;
/**
*
* @param letter
*/
export declare function badJsDocs(letter: string): string;
/**
* Makes a letter upper case.
* @param {string} letter Either upper or lower case.
* @returns {string} Upper case letter
*/
export declare function goodJsDocs(letter: string): string;
12 changes: 12 additions & 0 deletions samples/jsdoc.sample.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
/* eslint-disable unicorn/prevent-abbreviations */
function noJsDocs() {
// No JS Doc error
return false;
}
export function exportedNoJsDocs() {
// No JS Doc error
return noJsDocs();
}
export const one = 1;
/**
*
* @param letter
*/
export function badJsDocs(letter) {
return letter.toLowerCase();
}
/**
* Makes a letter upper case.
* @param {string} letter Either upper or lower case.
* @returns {string} Upper case letter
*/
export function goodJsDocs(letter) {
return letter.toUpperCase();
}
15 changes: 15 additions & 0 deletions samples/main.sample.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,38 @@
/*
This
file
is
intentionally
horrible.
*/
import fs from 'fs';
import 'missing-package';
import './missing';
const FilePath = __dirname + '/file.txt';
/**
* whitelist - not blacklist
*/
const whitelist = ['a', 'b', 'c'];
let maxVal = 50 > 100 ? 50 : 100;
fs.exists(FilePath);
var emailExpression = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
const API_KEY = "ZWVTjPQSdhwRgl204Hc51YCsritMIzn8B=/p9UyeX7xu6KkAGqfm3FJ+oObLDNEva";
export async function test_fn(varName) {
// This file is formatted badly on purpose to ennsure the
// ESLint configuration is loadng correctly.
var VAR = /[0-9\d]/g;
return varName + 'test' + ' ' + 2;
}
export default function () {
/** test */
return !false;
}
let tmp = `test`;
async function promiseTst(param1, param2, param3, param4, param5, param6) {
return new Promise(function (reject, resolve) {
for (let i = 1; i <= 1; i++) {
//
}
if (1 == 1)
return 'test' + 'test' + 'test' + 'test' + 'test';
Expand Down
13 changes: 13 additions & 0 deletions test/runEslint.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
// eslint-disable-next-line @eslint-community/eslint-comments/disable-enable-pair
/* eslint-disable @typescript-eslint/no-magic-numbers */
import { exec } from 'node:child_process';
const eslintCommand = 'eslint --config ./test/eslint.testWebappConfig.js --exit-on-fatal-error ./samples/*.sample.ts';
console.log(`Running ${eslintCommand} ...`);
try {
// eslint-disable-next-line sonarjs/no-os-command-from-path, sonarjs/os-command
exec(eslintCommand, (error, stdout, stderr) => {
/*
* Print output
*/
if (stdout !== '') {
console.log('\nSTDOUT');
console.log(stdout);
Expand All @@ -11,6 +17,9 @@ try {
console.log('\nSTDERR');
console.log(stderr);
}
/*
* Check if processed
*/
if (error === null) {
console.log('❗ ESLint did not find any errors or warnings.');
process.exitCode = 1;
Expand All @@ -23,6 +32,9 @@ try {
console.log('✔️ ESLint errors and warnings found. Config checked successfully.');
process.exitCode = 0;
}
/*
* Check if all imported plugins used
*/
console.log('\nPLUGINS TESTED');
const pluginStrings = [
'@cspell/',
Expand All @@ -38,6 +50,7 @@ try {
'security/',
'sonarjs/',
'unicorn/',
// 'woke/',
'write-good-comments/'
];
const outputLines = stdout.split('\n');
Expand Down
5 changes: 2 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
{
"compilerOptions": {
"target": "es2022",
"target": "ES2022",
"module": "Node16",
"moduleResolution": "Node16",
"declaration": true,
"strictNullChecks": true,
"allowSyntheticDefaultImports": true,
"removeComments": true
"allowSyntheticDefaultImports": true
},
"compileOnSave": true,
"buildOnSave": true,
Expand Down
3 changes: 3 additions & 0 deletions wordLists/cspell.flagWords.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
/**
* Words that will be flagged as not allowed.
*/
export declare const flagWords: string[];
export default flagWords;
7 changes: 7 additions & 0 deletions wordLists/cspell.flagWords.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import list2 from 'eslint-plugin-woke/lib/categories/gender.js';
import list3 from 'eslint-plugin-woke/lib/categories/profanity.js';
import list4 from 'eslint-plugin-woke/lib/categories/racism.js';
import { words } from './cspell.words.js';
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const unformattedWordLists = [...list1, ...list2, ...list3, ...list4];
const wordListSet = new Set();
for (const unformattedWordList of unformattedWordLists) {
Expand All @@ -15,8 +16,14 @@ for (const unformattedWordList of unformattedWordLists) {
}
}
}
/**
* Remove all allowed words
*/
for (const wordToRemove of words) {
wordListSet.delete(wordToRemove);
}
/**
* Words that will be flagged as not allowed.
*/
export const flagWords = [...wordListSet];
export default flagWords;
3 changes: 3 additions & 0 deletions wordLists/cspell.words.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
/**
* Words that will be treated as valid.
*/
export declare const words: string[];
export default words;
8 changes: 8 additions & 0 deletions wordLists/cspell.words.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
/**
* Words that will be treated as valid.
*/
export const words = [
/* City of Sault Ste. Marie words */
'cityssm',
'saultstemarie',
/* CitySSM Web App words */
'datetimepicker',
'fullwidth',
'hoverable',
Expand All @@ -10,11 +15,14 @@ export const words = [
'trash',
'vcentered',
'yellow',
/* Database-related words */
'ifnull',
'nvarchar',
'recordset',
/* Linter words */
'sonarjs',
'tseslint',
/* Other words */
'millis'
];
export default words;
3 changes: 3 additions & 0 deletions wordLists/writeGoodComments.whitelist.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
/**
* Words that will not be flagged by write-good-comments.
*/
export declare const whitelist: string[];
export default whitelist;
5 changes: 5 additions & 0 deletions wordLists/writeGoodComments.whitelist.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
// eslint-disable-next-line @eslint-community/eslint-comments/disable-enable-pair
/* eslint-disable @cspell/spellchecker */
/**
* Words that will not be flagged by write-good-comments.
*/
export const whitelist = ['only', 'validate'];
export default whitelist;
3 changes: 3 additions & 0 deletions wordLists/writeGoodComments.whitelist.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// eslint-disable-next-line @eslint-community/eslint-comments/disable-enable-pair
/* eslint-disable @cspell/spellchecker */

/**
* Words that will not be flagged by write-good-comments.
*/
export const whitelist = ['only', 'validate']

export default whitelist

0 comments on commit b4407f3

Please sign in to comment.