From c238aea2b988eeebcf76a51f69b43e6c2d30b919 Mon Sep 17 00:00:00 2001 From: kekee000 Date: Wed, 30 Jun 2021 12:01:42 +0800 Subject: [PATCH] lint: modify lint rules --- .eslintignore | 2 +- .eslintrc.js | 25 ++++++++++++++++++++++--- package.json | 7 ++++--- src/graphics/pathUtil.js | 2 +- src/ttf/table/cff/parseCFFGlyph.js | 14 +++++++------- src/ttf/table/glyf/sizeof.js | 2 +- src/ttf/ttf2svg.js | 3 ++- src/ttf/ttf2symbol.js | 6 +++--- src/ttf/ttf2woff.js | 2 +- src/ttf/util/contour2svg.js | 2 +- src/ttf/woff2ttf.js | 2 +- test/node-spec/adjustttf.spec.js | 2 +- test/node-spec/font.spec.js | 2 +- test/node-spec/otf2ttf.spec.js | 2 +- test/node-spec/readotf.spec.js | 2 +- test/node-spec/readttf.spec.js | 2 +- test/node-spec/writettf.spec.js | 2 +- test/spec/ttf/font.spec.js | 3 +-- test/spec/ttf/ttf2woff.spec.js | 1 - test/spec/ttf/woff2.spec.js | 29 ++++++++++++++--------------- 20 files changed, 65 insertions(+), 47 deletions(-) diff --git a/.eslintignore b/.eslintignore index afe778f..7b5cba3 100644 --- a/.eslintignore +++ b/.eslintignore @@ -2,5 +2,5 @@ src/ttf/data/* demo/* node_modules release -test +test/data tool \ No newline at end of file diff --git a/.eslintrc.js b/.eslintrc.js index 1022f81..7aedc2d 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -3,9 +3,10 @@ module.exports = { 'env': { 'browser': true, 'es2021': true, - 'node': true + 'node': true, + 'mocha': true }, - 'extends': ['eslint:recommended', 'esnext'], + 'extends': ['eslint:recommended', 'plugin:import/recommended'], 'parserOptions': { 'ecmaVersion': 12, 'sourceType': 'module' @@ -34,6 +35,24 @@ module.exports = { 'null': 'ignore' } ], + 'key-spacing': [ + 2, + { + beforeColon: false, + afterColon: true + } + ], + 'no-multi-spaces': 2, 'class-methods-use-this': 0 - } + }, + 'overrides': [ + { + files: [ + 'test/**/*.js' + ], + rules: { + 'import/no-unresolved': 0 + } + } + ] }; diff --git a/package.json b/package.json index 5443acb..341f849 100644 --- a/package.json +++ b/package.json @@ -36,11 +36,12 @@ "scripts": { "precommit": "npm run lint", "publish:npm": "npm run build && npm publish --registry=https://registry.npmjs.org/", - "test": "./node_modules/.bin/mocha --require @babel/register test/spec/*.spec.js test/spec/**/*.spec.js", + "test": "npm run test:browser && npm run test:node", + "test:browser": "./node_modules/.bin/mocha --require @babel/register test/spec/*.spec.js test/spec/**/*.spec.js", "test:node": "npm run build && ./node_modules/mocha/bin/mocha test/node-spec/**/*.spec.js ", "dev": "webpack-dev-server --open --config ./config/webpack.dev.js", "build": "babel src --out-dir lib", - "lint": "eslint ./src" + "lint": "eslint ./src ./test" }, "husky": { "hooks": { @@ -77,7 +78,7 @@ "commander": "^3.0.2", "css-loader": "^3.2.0", "eslint": "^7.9.0", - "eslint-config-esnext": "^4.1.0", + "eslint-plugin-import": "^2.23.4", "html-webpack-plugin": "^3.2.0", "husky": "^4.3.0", "lint-staged": "^10.4.0", diff --git a/src/graphics/pathUtil.js b/src/graphics/pathUtil.js index 49e201d..d2431da 100644 --- a/src/graphics/pathUtil.js +++ b/src/graphics/pathUtil.js @@ -91,7 +91,7 @@ export function isClockWise(path) { return zCount === 0 ? 0 - : zCount < 0 ? 1 : -1; + : zCount < 0 ? 1 : -1; } /** diff --git a/src/ttf/table/cff/parseCFFGlyph.js b/src/ttf/table/cff/parseCFFGlyph.js index 6c6534e..32b486e 100644 --- a/src/ttf/table/cff/parseCFFGlyph.js +++ b/src/ttf/table/cff/parseCFFGlyph.js @@ -170,8 +170,8 @@ export default function parseCFFCharstring(code, font, index) { switch (v) { case 35: // flex // |- dx1 dy1 dx2 dy2 dx3 dy3 dx4 dy4 dx5 dy5 dx6 dy6 fd flex (12 35) |- - c1x = x + stack.shift(); // dx1 - c1y = y + stack.shift(); // dy1 + c1x = x + stack.shift(); // dx1 + c1y = y + stack.shift(); // dy1 c2x = c1x + stack.shift(); // dx2 c2y = c1y + stack.shift(); // dy2 jpx = c2x + stack.shift(); // dx3 @@ -188,7 +188,7 @@ export default function parseCFFCharstring(code, font, index) { break; case 34: // hflex // |- dx1 dx2 dy2 dx3 dx4 dx5 dx6 hflex (12 34) |- - c1x = x + stack.shift(); // dx1 + c1x = x + stack.shift(); // dx1 c1y = y; // dy1 c2x = c1x + stack.shift(); // dx2 c2y = c1y + stack.shift(); // dy2 @@ -204,8 +204,8 @@ export default function parseCFFCharstring(code, font, index) { break; case 36: // hflex1 // |- dx1 dy1 dx2 dy2 dx3 dx4 dx5 dy5 dx6 hflex1 (12 36) |- - c1x = x + stack.shift(); // dx1 - c1y = y + stack.shift(); // dy1 + c1x = x + stack.shift(); // dx1 + c1y = y + stack.shift(); // dy1 c2x = c1x + stack.shift(); // dx2 c2y = c1y + stack.shift(); // dy2 jpx = c2x + stack.shift(); // dx3 @@ -220,8 +220,8 @@ export default function parseCFFCharstring(code, font, index) { break; case 37: // flex1 // |- dx1 dy1 dx2 dy2 dx3 dy3 dx4 dy4 dx5 dy5 d6 flex1 (12 37) |- - c1x = x + stack.shift(); // dx1 - c1y = y + stack.shift(); // dy1 + c1x = x + stack.shift(); // dx1 + c1y = y + stack.shift(); // dy1 c2x = c1x + stack.shift(); // dx2 c2y = c1y + stack.shift(); // dy2 jpx = c2x + stack.shift(); // dx3 diff --git a/src/ttf/table/glyf/sizeof.js b/src/ttf/table/glyf/sizeof.js index d6ea233..3135c3e 100644 --- a/src/ttf/table/glyf/sizeof.js +++ b/src/ttf/table/glyf/sizeof.js @@ -61,7 +61,7 @@ function sizeofCompound(glyf, hinting) { size += 8; } // scale - else if (transform.a !== 1 || transform.d !== 1) { + else if (transform.a !== 1 || transform.d !== 1) { size += transform.a === transform.d ? 2 : 4; } diff --git a/src/ttf/ttf2svg.js b/src/ttf/ttf2svg.js index 74e82e6..8c0d91e 100644 --- a/src/ttf/ttf2svg.js +++ b/src/ttf/ttf2svg.js @@ -18,6 +18,7 @@ import config from './data/default'; const SVG_FONT_ID = config.fontId; // xml 模板 +/* eslint-disable no-multi-spaces */ const XML_TPL = '' + '' + '' @@ -32,7 +33,7 @@ const XML_TPL = '' + '${glyphList}' + '' + ''; - +/* eslint-enable no-multi-spaces */ // glyph 模板 const GLYPH_TPL = ''; diff --git a/src/ttf/ttf2symbol.js b/src/ttf/ttf2symbol.js index 31b7a5b..500a4e2 100644 --- a/src/ttf/ttf2symbol.js +++ b/src/ttf/ttf2symbol.js @@ -12,14 +12,14 @@ import error from './error'; // xml 模板 const XML_TPL = '' + '' - + '${symbolList}' + + ' xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">' + + '${symbolList}' + ''; // symbol 模板 const SYMBOL_TPL = '' + '' - + '' + + '' + ''; diff --git a/src/ttf/ttf2woff.js b/src/ttf/ttf2woff.js index 66fae3e..b54b765 100644 --- a/src/ttf/ttf2woff.js +++ b/src/ttf/ttf2woff.js @@ -9,7 +9,7 @@ * https://github.com/fontello/ttf2woff * https://github.com/nodeca/pako */ - +/* eslint-disable no-multi-spaces */ import Reader from './reader'; import Writer from './writer'; import string from '../common/string'; diff --git a/src/ttf/util/contour2svg.js b/src/ttf/util/contour2svg.js index deed2a2..43dd02f 100644 --- a/src/ttf/util/contour2svg.js +++ b/src/ttf/util/contour2svg.js @@ -44,7 +44,7 @@ export default function contour2svg(contour, precision = 2) { else { x = (prevPoint.x + curPoint.x) / 2; y = (prevPoint.y + curPoint.y) / 2; - pathArr.push('M' + ceil(x) + ' ' + ceil(y)); + pathArr.push('M' + ceil(x) + ' ' + ceil(y)); } } diff --git a/src/ttf/woff2ttf.js b/src/ttf/woff2ttf.js index 5e9e9f8..a63aadf 100644 --- a/src/ttf/woff2ttf.js +++ b/src/ttf/woff2ttf.js @@ -27,7 +27,7 @@ export default function woff2ttf(woffBuffer, options = {}) { } const numTables = reader.readUint16(12); - const ttfSize = reader.readUint32(16); + const ttfSize = reader.readUint32(16); const tableEntries = []; let tableEntry; let i; diff --git a/test/node-spec/adjustttf.spec.js b/test/node-spec/adjustttf.spec.js index 416bafd..7b338dc 100644 --- a/test/node-spec/adjustttf.spec.js +++ b/test/node-spec/adjustttf.spec.js @@ -2,7 +2,7 @@ * @file adjustttf * @author mengke01(kekee000@gmail.com) */ -/* globals Int8Array */ + const assert = require('assert'); const fs = require('fs'); const TTFReader = require('./fonteditor-core').TTFReader; diff --git a/test/node-spec/font.spec.js b/test/node-spec/font.spec.js index a4938d1..82866ed 100644 --- a/test/node-spec/font.spec.js +++ b/test/node-spec/font.spec.js @@ -2,7 +2,7 @@ * @file font * @author mengke01(kekee000@gmail.com) */ -/* globals Int8Array, before */ + const assert = require('assert'); const fs = require('fs'); const Font = require('./fonteditor-core').Font; diff --git a/test/node-spec/otf2ttf.spec.js b/test/node-spec/otf2ttf.spec.js index 377f052..9cec59c 100644 --- a/test/node-spec/otf2ttf.spec.js +++ b/test/node-spec/otf2ttf.spec.js @@ -12,7 +12,7 @@ const util = require('./util'); function readotf(file) { let data = fs.readFileSync(file); let buffer = util.toArrayBuffer(data); - let fontObject = new OTFReader().read(buffer); + let fontObject = new OTFReader().read(buffer); return fontObject; } diff --git a/test/node-spec/readotf.spec.js b/test/node-spec/readotf.spec.js index 69b64b1..9075fad 100644 --- a/test/node-spec/readotf.spec.js +++ b/test/node-spec/readotf.spec.js @@ -6,7 +6,7 @@ const util = require('./util'); function readotf(file) { var data = fs.readFileSync(file); var buffer = util.toArrayBuffer(data); - var fontObject = new OTFReader().read(buffer); + var fontObject = new OTFReader().read(buffer); return fontObject; } diff --git a/test/node-spec/readttf.spec.js b/test/node-spec/readttf.spec.js index 629bbed..16062f1 100644 --- a/test/node-spec/readttf.spec.js +++ b/test/node-spec/readttf.spec.js @@ -12,7 +12,7 @@ const util = require('./util'); function readttf(file) { var data = fs.readFileSync(file); var buffer = util.toArrayBuffer(data); - var ttfObject = new TTFReader().read(buffer); + var ttfObject = new TTFReader().read(buffer); return ttfObject; } diff --git a/test/node-spec/writettf.spec.js b/test/node-spec/writettf.spec.js index eb88113..697ed58 100644 --- a/test/node-spec/writettf.spec.js +++ b/test/node-spec/writettf.spec.js @@ -20,7 +20,7 @@ function readttf(file) { describe('readoft', function () { it('readoft', function () { let buffer = readttf(__dirname + '/../data/bebas.ttf'); - let ttfObject = new TTFReader().read(buffer); + let ttfObject = new TTFReader().read(buffer); assert(ttfObject.name.fontFamily === 'Bebas', 'test read ttf'); assert(JSON.stringify(ttfObject), 'test writettf'); diff --git a/test/spec/ttf/font.spec.js b/test/spec/ttf/font.spec.js index 68d2136..bcc35f4 100644 --- a/test/spec/ttf/font.spec.js +++ b/test/spec/ttf/font.spec.js @@ -2,8 +2,7 @@ * @file font * @author mengke01(kekee000@gmail.com) */ -/* eslint-disable fecs-no-require */ -/* globals before */ + import assert from 'assert'; import {readData} from '../data'; import Font from 'fonteditor-core/ttf/font'; diff --git a/test/spec/ttf/ttf2woff.spec.js b/test/spec/ttf/ttf2woff.spec.js index f6d9843..0d19a30 100644 --- a/test/spec/ttf/ttf2woff.spec.js +++ b/test/spec/ttf/ttf2woff.spec.js @@ -9,7 +9,6 @@ import TTFReader from 'fonteditor-core/ttf/ttfreader'; import ttf2woff from 'fonteditor-core/ttf/ttf2woff'; import woff2ttf from 'fonteditor-core/ttf/woff2ttf'; import pako from 'pako'; -import { fstat } from 'fs'; describe('ttf to woff', function () { diff --git a/test/spec/ttf/woff2.spec.js b/test/spec/ttf/woff2.spec.js index 509ca3a..22e2337 100644 --- a/test/spec/ttf/woff2.spec.js +++ b/test/spec/ttf/woff2.spec.js @@ -2,7 +2,6 @@ * @file woff2 enc and dec * @author mengke01(kekee000@gmail.com) */ -/* globals before */ import assert from 'assert'; import {readData} from '../data'; @@ -44,13 +43,13 @@ describe('woff2', function () { assert.ok(result.byteLength); return woff2tottf(result); }) - .then(function (result) { - assert.ok(result.byteLength); - let fontObject = new TTFReader().read(result); - assert.equal(fontObject.version, 1); - assert.equal(fontObject.numTables, 16); - done(); - }); + .then(function (result) { + assert.ok(result.byteLength); + let fontObject = new TTFReader().read(result); + assert.equal(fontObject.version, 1); + assert.equal(fontObject.numTables, 16); + done(); + }); }); it('woff2tottfasync', function (done) { @@ -68,13 +67,13 @@ describe('woff2', function () { assert.ok(result.byteLength); return woff2tottfasync(result); }) - .then(function (result) { - assert.ok(result.byteLength); - let fontObject = new TTFReader().read(result); - assert.equal(fontObject.version, 1); - assert.equal(fontObject.numTables, 14); - done(); - }); + .then(function (result) { + assert.ok(result.byteLength); + let fontObject = new TTFReader().read(result); + assert.equal(fontObject.version, 1); + assert.equal(fontObject.numTables, 14); + done(); + }); }); it('woff2tottfasync compound', function (done) {