From b8a70e15be727c118cc582d3c60f3126a501d169 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Sun, 19 Mar 2023 11:22:33 +0200 Subject: [PATCH] Minor lint fixes --- index.js | 8 ++++---- test/index.js | 27 ++++++++++++++------------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/index.js b/index.js index d90305e..6d5885a 100644 --- a/index.js +++ b/index.js @@ -161,17 +161,17 @@ precinct.paperwork = (filename, options = {}) => { const dependencies = precinct(content, options); if (!options.includeCore) { - return dependencies.filter((dependency) => { + return dependencies.filter(dependency => { if (dependency.startsWith('node:')) { - return false + return false; } - // In nodejs 18, node:test is a builtin but shows up under natives["test"], but + // In Node.js 18, node:test is a builtin but shows up under natives["test"], but // can only be imported by "node:test." We're correcting this so "test" isn't // unnecessarily stripped from the imports if (dependency === 'test') { debug('paperwork: allowing test import to avoid builtin/natives consideration\n'); - return true + return true; } return !natives[dependency]; diff --git a/test/index.js b/test/index.js index 6559828..879defc 100644 --- a/test/index.js +++ b/test/index.js @@ -7,7 +7,8 @@ const fs = require('fs'); const path = require('path'); const rewire = require('rewire'); const sinon = require('sinon'); -const ast = require('./fixtures/exampleAST'); +const ast = require('./fixtures/exampleAST.js'); + const precinct = rewire('../index.js'); function read(filename) { @@ -163,7 +164,7 @@ describe('node-precinct', () => { describe('paperwork', () => { it('grabs dependencies of jsx files', () => { - const result = precinct.paperwork(`${__dirname}/fixtures/module.jsx`); + const result = precinct.paperwork(path.join(__dirname, '/fixtures/module.jsx')); const expected = ['./es6NoImport']; assert.deepEqual(result, expected); @@ -186,10 +187,10 @@ describe('node-precinct', () => { }); it('returns the dependencies for the given filepath', () => { - assert.notEqual(precinct.paperwork(`${__dirname}/fixtures/es6.js`).length, 0); - assert.notEqual(precinct.paperwork(`${__dirname}/fixtures/styles.scss`).length, 0); - assert.notEqual(precinct.paperwork(`${__dirname}/fixtures/typescript.ts`).length, 0); - assert.notEqual(precinct.paperwork(`${__dirname}/fixtures/styles.css`).length, 0); + assert.notEqual(precinct.paperwork(path.join(__dirname, '/fixtures/es6.js')).length, 0); + assert.notEqual(precinct.paperwork(path.join(__dirname, '/fixtures/styles.scss')).length, 0); + assert.notEqual(precinct.paperwork(path.join(__dirname, '/fixtures/typescript.ts')).length, 0); + assert.notEqual(precinct.paperwork(path.join(__dirname, '/fixtures/styles.css')).length, 0); }); it('throws if the file cannot be found', () => { @@ -199,7 +200,7 @@ describe('node-precinct', () => { }); it('filters out core modules if options.includeCore is false', () => { - const deps = precinct.paperwork(`${__dirname}/fixtures/coreModules.js`, { + const deps = precinct.paperwork(path.join(__dirname, '/fixtures/coreModules.js'), { includeCore: false }); @@ -207,13 +208,13 @@ describe('node-precinct', () => { }); it('handles cjs files as commonjs', () => { - const deps = precinct.paperwork(`${__dirname}/fixtures/commonjs.cjs`); + const deps = precinct.paperwork(path.join(__dirname, '/fixtures/commonjs.cjs')); assert.equal(deps.includes('./a'), true); assert.equal(deps.includes('./b'), true); }); it('does not filter out core modules by default', () => { - const deps = precinct.paperwork(`${__dirname}/fixtures/coreModules.js`); + const deps = precinct.paperwork(path.join(__dirname, '/fixtures/coreModules.js')); assert.notEqual(deps.length, 0); }); @@ -226,7 +227,7 @@ describe('node-precinct', () => { } }; - precinct.paperwork(`${__dirname}/fixtures/amd.js`, { + precinct.paperwork(path.join(__dirname, '/fixtures/amd.js'), { includeCore: false, amd: config.amd }); @@ -240,7 +241,7 @@ describe('node-precinct', () => { const stub = sinon.stub().returns([]); const revert = precinct.__set__('precinct', stub); - precinct.paperwork(`${__dirname}/fixtures/amd.js`, { + precinct.paperwork(path.join(__dirname, '/fixtures/amd.js'), { amd: { skipLazyLoaded: true } @@ -349,12 +350,12 @@ describe('node-precinct', () => { assert.deepEqual(deps, ['streams']); }); - it("understands quirks around some modules only being addressable via node: prefix", () => { + it('understands quirks around some modules only being addressable via node: prefix', () => { const deps = precinct.paperwork(path.join(__dirname, 'fixtures', 'requiretest.js'), { includeCore: false }); assert.deepEqual(deps, ['test']); - }) + }); }); describe('that uses dynamic imports', () => {