Comparing version 1.0.16 to 1.0.17
#!/usr/bin/env node | ||
import cli from 'commander'; | ||
import { join } from 'path'; | ||
import jqkill from '../src/jqkill.js'; | ||
import { basePath, readContents, readPkg, match } from '../src/util/index.js'; | ||
import cli from 'commander' | ||
import { join } from 'path' | ||
import jqkill from '../src/jqkill.js' | ||
import { basePath, readContents, readPkg, match } from '../src/util/index.js' | ||
const DEFAULT_PATTERN = '**/*.js'; | ||
const DEFAULT_IGNORE = '**/node_modules/**'; | ||
const DEFAULT_PATTERN = '**/*.js' | ||
const DEFAULT_IGNORE = '**/node_modules/**' | ||
const DEFAULT_ROOT = process.cwd(); | ||
(async () => { | ||
const pkg = await readPkg(); | ||
const pkg = await readPkg() | ||
@@ -18,26 +18,26 @@ cli.version(pkg.version) | ||
.option('-r, --root [value]', 'The root path') | ||
.parse(process.argv); | ||
.parse(process.argv) | ||
// prep the input | ||
const pattern = cli.args[0] ? cli.args[0] : DEFAULT_PATTERN; | ||
const ignore = cli.ignore ? cli.ignore : DEFAULT_IGNORE; | ||
const root = cli.root ? cli.root : DEFAULT_ROOT; | ||
const pattern = cli.args[0] ? cli.args[0] : DEFAULT_PATTERN | ||
const ignore = cli.ignore ? cli.ignore : DEFAULT_IGNORE | ||
const root = cli.root ? cli.root : DEFAULT_ROOT | ||
// glob match to fetch the test file list | ||
const files = await match(pattern, ignore, root); | ||
var globalResult = false; | ||
const files = await match(pattern, ignore, root) | ||
var globalResult = false | ||
for (const path of files) { | ||
const contents = await readContents(path); | ||
const fullPath = join(basePath, path); | ||
const result = jqkill(contents, fullPath); | ||
if (result) { globalResult = true; } | ||
const contents = await readContents(path) | ||
const fullPath = join(basePath, path) | ||
const result = jqkill(contents, fullPath) | ||
if (result) { globalResult = true } | ||
} | ||
if (globalResult) { | ||
process.exitCode = 1; | ||
console.error('\x1b[31m%s\x1b[0m %s', 'ERR', 'jQuery found!'); | ||
process.exitCode = 1 | ||
console.error('\x1b[31m%s\x1b[0m %s', 'ERR', 'jQuery found!') | ||
} | ||
})().catch(e => { | ||
console.error(e); | ||
}); | ||
console.error(e) | ||
}) |
{ | ||
"name": "jqkill", | ||
"version": "1.0.16", | ||
"version": "1.0.17", | ||
"description": "A linter to help locate and eliminate jQuery", | ||
@@ -22,3 +22,3 @@ "keywords": [ | ||
"test:watch": "tape-watch-es", | ||
"lint": "semistandard", | ||
"lint": "esmtk lint", | ||
"package": "npx rimraf package && npm pack | tail -n 1 | xargs tar -xf", | ||
@@ -33,8 +33,6 @@ "preversion": "npm run lint && npm run test", | ||
"devDependencies": { | ||
"babel-eslint": "^10.0.3", | ||
"semistandard": "^14.2.0", | ||
"esmtk": "^0.1.1", | ||
"tape-es": "^1.2.5" | ||
}, | ||
"semistandard": { | ||
"parser": "babel-eslint", | ||
"standard": { | ||
"ignore": [ | ||
@@ -41,0 +39,0 @@ "**/__test__/*" |
@@ -10,5 +10,5 @@ /* eslint-disable no-new-func */ | ||
export default function JQKill (contents = '', path = null) { | ||
let matches = []; | ||
let match = ''; | ||
let state = 0; | ||
let matches = [] | ||
let match = '' | ||
let state = 0 | ||
const hit = { | ||
@@ -19,11 +19,11 @@ path, | ||
row: null | ||
}; | ||
let row = 1; | ||
let col = 1; | ||
let result = false; | ||
} | ||
let row = 1 | ||
let col = 1 | ||
let result = false | ||
const lexer = RegExp(/\$|\(|\w+\(|\.|\)|\r\n|\n|\r|[^$.)\r\n]+/y); | ||
const lexer = RegExp(/\$|\(|\w+\(|\.|\)|\r\n|\n|\r|[^$.)\r\n]+/y) | ||
while ((matches = lexer.exec(contents)) !== null) { | ||
match = matches[0]; | ||
match = matches[0] | ||
@@ -34,81 +34,81 @@ switch (state) { | ||
case match === '$': | ||
state = 1; | ||
hit.value += match; | ||
hit.row = row; | ||
hit.col = col; | ||
col += match.length; | ||
break; | ||
state = 1 | ||
hit.value += match | ||
hit.row = row | ||
hit.col = col | ||
col += match.length | ||
break | ||
case /^(\r\n|\n|\r)$/.test(match): | ||
state = 0; | ||
col = 1; | ||
row += 1; | ||
break; | ||
state = 0 | ||
col = 1 | ||
row += 1 | ||
break | ||
default: | ||
state = 0; | ||
col += match.length; | ||
break; | ||
state = 0 | ||
col += match.length | ||
break | ||
} | ||
break; | ||
break | ||
case 1: // is function? | ||
switch (true) { | ||
case match === '(': | ||
state = 2; | ||
hit.value += match; | ||
col += match.length; | ||
break; | ||
state = 2 | ||
hit.value += match | ||
col += match.length | ||
break | ||
case /\w+\(/.test(match): | ||
state = 2; | ||
hit.value += match; | ||
col += match.length; | ||
break; | ||
state = 2 | ||
hit.value += match | ||
col += match.length | ||
break | ||
case match === '.': | ||
state = 1; | ||
hit.value += match; | ||
break; | ||
state = 1 | ||
hit.value += match | ||
break | ||
default: | ||
state = 0; | ||
flush(hit); | ||
break; | ||
state = 0 | ||
flush(hit) | ||
break | ||
} | ||
break; | ||
break | ||
case 2: // value | ||
switch (true) { | ||
case match === ')' && lexer.lastIndex === contents.length: | ||
hit.value += match; | ||
result = true; | ||
kill(hit); | ||
break; | ||
hit.value += match | ||
result = true | ||
kill(hit) | ||
break | ||
case match === ')': | ||
state = 3; | ||
hit.value += match; | ||
break; | ||
state = 3 | ||
hit.value += match | ||
break | ||
default: | ||
state = 2; | ||
hit.value += match; | ||
break; | ||
state = 2 | ||
hit.value += match | ||
break | ||
} | ||
break; | ||
break | ||
case 3: // is end? | ||
switch (true) { | ||
case match === '.': | ||
state = 1; | ||
hit.value += match; | ||
break; | ||
state = 1 | ||
hit.value += match | ||
break | ||
case /^(\r\n|\n|\r)$/.test(match): | ||
state = 0; | ||
col = 1; | ||
row += 1; | ||
result = true; | ||
kill(hit); | ||
break; | ||
state = 0 | ||
col = 1 | ||
row += 1 | ||
result = true | ||
kill(hit) | ||
break | ||
default: | ||
state = 0; | ||
result = true; | ||
kill(hit); | ||
break; | ||
state = 0 | ||
result = true | ||
kill(hit) | ||
break | ||
} | ||
break; | ||
break | ||
} | ||
} | ||
return result; | ||
return result | ||
} | ||
@@ -119,11 +119,11 @@ | ||
? `${hit.path}:` | ||
: ''; | ||
console.error(`${path}${hit.row}:${hit.col}: ${hit.value}`); | ||
flush(hit); | ||
: '' | ||
console.error(`${path}${hit.row}:${hit.col}: ${hit.value}`) | ||
flush(hit) | ||
} | ||
function flush (hit) { | ||
hit.value = ''; | ||
hit.row = null; | ||
hit.col = null; | ||
hit.value = '' | ||
hit.row = null | ||
hit.col = null | ||
} |
/* eslint-disable no-template-curly-in-string */ | ||
import test from 'tape'; | ||
import jqkill from './jqkill.js'; | ||
import { readFixture } from './util/index.js'; | ||
import test from 'tape' | ||
import jqkill from './jqkill.js' | ||
import { readFixture } from './util/index.js' | ||
const consoleError = console.error; | ||
let errorOutput = []; | ||
const consoleError = console.error | ||
let errorOutput = [] | ||
const basic = readFixture('basic.js'); | ||
const chain = readFixture('chain.js'); | ||
const util = readFixture('util.js'); | ||
const semiColon = readFixture('semi-colon.js'); | ||
const mixed = readFixture('mixed.js'); | ||
const row1 = readFixture('row1.js'); | ||
const row2 = readFixture('row2.js'); | ||
const row3 = readFixture('row3.js'); | ||
const col1 = readFixture('col1.js'); | ||
const col2 = readFixture('col2.js'); | ||
const col3 = readFixture('col3.js'); | ||
const multi1 = readFixture('multi1.js'); | ||
const multi2 = readFixture('multi2.js'); | ||
const multi3 = readFixture('multi3.js'); | ||
const basic = readFixture('basic.js') | ||
const chain = readFixture('chain.js') | ||
const util = readFixture('util.js') | ||
const semiColon = readFixture('semi-colon.js') | ||
const mixed = readFixture('mixed.js') | ||
const row1 = readFixture('row1.js') | ||
const row2 = readFixture('row2.js') | ||
const row3 = readFixture('row3.js') | ||
const col1 = readFixture('col1.js') | ||
const col2 = readFixture('col2.js') | ||
const col3 = readFixture('col3.js') | ||
const multi1 = readFixture('multi1.js') | ||
const multi2 = readFixture('multi2.js') | ||
const multi3 = readFixture('multi3.js') | ||
test('setup', (t) => { | ||
console.error = e => { errorOutput.push(e); }; | ||
t.end(); | ||
}); | ||
console.error = e => { errorOutput.push(e) } | ||
t.end() | ||
}) | ||
@@ -32,10 +32,10 @@ test('Basic - should work with a jQuery selector', async (t) => { | ||
'1:1: $(\'#test\')' | ||
]; | ||
jqkill(basic); | ||
] | ||
jqkill(basic) | ||
t.deepEqual(errorOutput, expect); | ||
t.deepEqual(errorOutput, expect) | ||
errorOutput = []; | ||
t.end(); | ||
}); | ||
errorOutput = [] | ||
t.end() | ||
}) | ||
@@ -45,10 +45,10 @@ test('Chain - should work with a jQuery chain', async (t) => { | ||
'1:1: $(\'#test\').html( "Next Step..." )' | ||
]; | ||
jqkill(chain); | ||
] | ||
jqkill(chain) | ||
t.deepEqual(errorOutput, expect); | ||
t.deepEqual(errorOutput, expect) | ||
errorOutput = []; | ||
t.end(); | ||
}); | ||
errorOutput = [] | ||
t.end() | ||
}) | ||
@@ -58,10 +58,10 @@ test('Util - should work with a jQuery utility method', async (t) => { | ||
'1:1: $.csv(\'string\')' | ||
]; | ||
jqkill(util); | ||
] | ||
jqkill(util) | ||
t.deepEqual(errorOutput, expect); | ||
t.deepEqual(errorOutput, expect) | ||
errorOutput = []; | ||
t.end(); | ||
}); | ||
errorOutput = [] | ||
t.end() | ||
}) | ||
@@ -71,10 +71,10 @@ test('SemiColon - should work with a semicolon at the end', async (t) => { | ||
'1:1: $(\'#test\')' | ||
]; | ||
jqkill(semiColon); | ||
] | ||
jqkill(semiColon) | ||
t.deepEqual(errorOutput, expect); | ||
t.deepEqual(errorOutput, expect) | ||
errorOutput = []; | ||
t.end(); | ||
}); | ||
errorOutput = [] | ||
t.end() | ||
}) | ||
@@ -86,10 +86,10 @@ test('Mixed - should work with all jQuery forms intermixed', async (t) => { | ||
'3:1: $.csv(\'string\')' | ||
]; | ||
jqkill(mixed); | ||
] | ||
jqkill(mixed) | ||
t.deepEqual(errorOutput, expect); | ||
t.deepEqual(errorOutput, expect) | ||
errorOutput = []; | ||
t.end(); | ||
}); | ||
errorOutput = [] | ||
t.end() | ||
}) | ||
@@ -99,10 +99,10 @@ test('Row1 - should display the correct row value', async (t) => { | ||
'3:1: $(\'#test\')' | ||
]; | ||
jqkill(row1); | ||
] | ||
jqkill(row1) | ||
t.deepEqual(errorOutput, expect); | ||
t.deepEqual(errorOutput, expect) | ||
errorOutput = []; | ||
t.end(); | ||
}); | ||
errorOutput = [] | ||
t.end() | ||
}) | ||
@@ -112,10 +112,10 @@ test('Row2 - should display the correct row value with a chain', async (t) => { | ||
'3:1: $(\'#test\').html( "Next Step..." )' | ||
]; | ||
jqkill(row2); | ||
] | ||
jqkill(row2) | ||
t.deepEqual(errorOutput, expect); | ||
t.deepEqual(errorOutput, expect) | ||
errorOutput = []; | ||
t.end(); | ||
}); | ||
errorOutput = [] | ||
t.end() | ||
}) | ||
@@ -125,10 +125,10 @@ test('Row3 - should display the correct row value with a util method', async (t) => { | ||
'3:1: $.csv(\'string\')' | ||
]; | ||
jqkill(row3); | ||
] | ||
jqkill(row3) | ||
t.deepEqual(errorOutput, expect); | ||
t.deepEqual(errorOutput, expect) | ||
errorOutput = []; | ||
t.end(); | ||
}); | ||
errorOutput = [] | ||
t.end() | ||
}) | ||
@@ -138,10 +138,10 @@ test('Col1 - should display the correct column value', async (t) => { | ||
'1:3: $(\'#test\')' | ||
]; | ||
jqkill(col1); | ||
] | ||
jqkill(col1) | ||
t.deepEqual(errorOutput, expect); | ||
t.deepEqual(errorOutput, expect) | ||
errorOutput = []; | ||
t.end(); | ||
}); | ||
errorOutput = [] | ||
t.end() | ||
}) | ||
@@ -151,10 +151,10 @@ test('Col2 - should display the correct column value with a chain', async (t) => { | ||
'1:3: $(\'#test\').html( "Next Step..." )' | ||
]; | ||
jqkill(col2); | ||
] | ||
jqkill(col2) | ||
t.deepEqual(errorOutput, expect); | ||
t.deepEqual(errorOutput, expect) | ||
errorOutput = []; | ||
t.end(); | ||
}); | ||
errorOutput = [] | ||
t.end() | ||
}) | ||
@@ -164,10 +164,10 @@ test('Col3 - should display the correct column value with a util method', async (t) => { | ||
'1:3: $.csv(\'string\')' | ||
]; | ||
jqkill(col3); | ||
] | ||
jqkill(col3) | ||
t.deepEqual(errorOutput, expect); | ||
t.deepEqual(errorOutput, expect) | ||
errorOutput = []; | ||
t.end(); | ||
}); | ||
errorOutput = [] | ||
t.end() | ||
}) | ||
@@ -179,10 +179,10 @@ test('Multi1 - should work with multiple jQuery selectors', async (t) => { | ||
'3:1: $(\'#test\')' | ||
]; | ||
jqkill(multi1); | ||
] | ||
jqkill(multi1) | ||
t.deepEqual(errorOutput, expect); | ||
t.deepEqual(errorOutput, expect) | ||
errorOutput = []; | ||
t.end(); | ||
}); | ||
errorOutput = [] | ||
t.end() | ||
}) | ||
@@ -194,10 +194,10 @@ test('Multi2 - should work with multiple jQuery chains', async (t) => { | ||
'3:1: $(\'#test\').html( "Next Step..." )' | ||
]; | ||
jqkill(multi2); | ||
] | ||
jqkill(multi2) | ||
t.deepEqual(errorOutput, expect); | ||
t.deepEqual(errorOutput, expect) | ||
errorOutput = []; | ||
t.end(); | ||
}); | ||
errorOutput = [] | ||
t.end() | ||
}) | ||
@@ -209,14 +209,14 @@ test('Multi3 - should work with multiple jQuery util methods', async (t) => { | ||
'3:1: $.csv(\'string\')' | ||
]; | ||
jqkill(multi3); | ||
] | ||
jqkill(multi3) | ||
t.deepEqual(errorOutput, expect); | ||
t.deepEqual(errorOutput, expect) | ||
errorOutput = []; | ||
t.end(); | ||
}); | ||
errorOutput = [] | ||
t.end() | ||
}) | ||
test('setup', (t) => { | ||
console.error = consoleError; | ||
t.end(); | ||
}); | ||
console.error = consoleError | ||
t.end() | ||
}) |
@@ -1,3 +0,3 @@ | ||
import { join } from 'path'; | ||
import { join } from 'path' | ||
export const basePath = join(process.cwd(), '/'); | ||
export const basePath = join(process.cwd(), '/') |
@@ -1,5 +0,5 @@ | ||
export { basePath } from './basePath.js'; | ||
export { match } from './match.js'; | ||
export { readContents } from './readContents.js'; | ||
export { readFixture } from './readFixture.js'; | ||
export { readPkg } from './readPkg.js'; | ||
export { basePath } from './basePath.js' | ||
export { match } from './match.js' | ||
export { readContents } from './readContents.js' | ||
export { readFixture } from './readFixture.js' | ||
export { readPkg } from './readPkg.js' |
import glob from 'glob'; | ||
import { promisify } from 'util'; | ||
const globAsync = promisify(glob); | ||
import glob from 'glob' | ||
import { promisify } from 'util' | ||
const globAsync = promisify(glob) | ||
@@ -9,6 +9,6 @@ export async function match (pattern, ignore, root) { | ||
if (ignore.includes(',')) { | ||
ignore = ignore.split(','); | ||
ignore = ignore.split(',') | ||
} | ||
return globAsync(pattern, { cwd: root, ignore }); | ||
return globAsync(pattern, { cwd: root, ignore }) | ||
} |
@@ -1,13 +0,13 @@ | ||
import { promises as fs } from 'fs'; | ||
import { promises as fs } from 'fs' | ||
export async function readContents (path) { | ||
if (!await fs.stat(path)) { | ||
throw Error(`${path} not found, is this a package?`); | ||
throw Error(`${path} not found, is this a package?`) | ||
} | ||
try { | ||
return await fs.readFile(path, 'utf-8'); | ||
return await fs.readFile(path, 'utf-8') | ||
} catch { | ||
throw Error(`Failed to read ${path}`); | ||
throw Error(`Failed to read ${path}`) | ||
} | ||
} |
@@ -1,6 +0,6 @@ | ||
import { readFileSync } from 'fs'; | ||
import { join } from 'path'; | ||
import { readFileSync } from 'fs' | ||
import { join } from 'path' | ||
export function readFixture (path) { | ||
return readFileSync(join(process.cwd(), 'src', '__test__', path), 'utf-8'); | ||
return readFileSync(join(process.cwd(), 'src', '__test__', path), 'utf-8') | ||
} |
@@ -1,14 +0,14 @@ | ||
import { promises as fs } from 'fs'; | ||
import { promises as fs } from 'fs' | ||
export async function readPkg () { | ||
const PKG_PATH = new URL('../../package.json', import.meta.url); | ||
const PKG_PATH = new URL('../../package.json', import.meta.url) | ||
if (!await fs.stat(PKG_PATH)) { | ||
throw Error('package.json not found, is this a package?'); | ||
throw Error('package.json not found, is this a package?') | ||
} | ||
try { | ||
return JSON.parse(await fs.readFile(PKG_PATH, 'utf-8')); | ||
return JSON.parse(await fs.readFile(PKG_PATH, 'utf-8')) | ||
} catch { | ||
throw Error('Failed to read package.json'); | ||
throw Error('Failed to read package.json') | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2
12991
1