Skip to content

Commit

Permalink
lint: modify lint rules
Browse files Browse the repository at this point in the history
  • Loading branch information
kekee000 committed Jun 30, 2021
1 parent d22e702 commit c238aea
Show file tree
Hide file tree
Showing 20 changed files with 65 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ src/ttf/data/*
demo/*
node_modules
release
test
test/data
tool
25 changes: 22 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
}
}
]
};
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/graphics/pathUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export function isClockWise(path) {

return zCount === 0
? 0
: zCount < 0 ? 1 : -1;
: zCount < 0 ? 1 : -1;
}

/**
Expand Down
14 changes: 7 additions & 7 deletions src/ttf/table/cff/parseCFFGlyph.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/ttf/table/glyf/sizeof.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
3 changes: 2 additions & 1 deletion src/ttf/ttf2svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import config from './data/default';
const SVG_FONT_ID = config.fontId;

// xml 模板
/* eslint-disable no-multi-spaces */
const XML_TPL = ''
+ '<?xml version="1.0" standalone="no"?>'
+ '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" >'
Expand All @@ -32,7 +33,7 @@ const XML_TPL = ''
+ '${glyphList}'
+ '</font></defs>'
+ '</svg>';

/* eslint-enable no-multi-spaces */
// glyph 模板
const GLYPH_TPL = '<glyph glyph-name="${name}" unicode="${unicode}" d="${d}" />';

Expand Down
6 changes: 3 additions & 3 deletions src/ttf/ttf2symbol.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import error from './error';
// xml 模板
const XML_TPL = ''
+ '<svg style="position: absolute; width: 0; height: 0;" width="0" height="0" version="1.1"'
+ ' xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">'
+ '<defs>${symbolList}</defs>'
+ ' xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">'
+ '<defs>${symbolList}</defs>'
+ '</svg>';

// symbol 模板
const SYMBOL_TPL = ''
+ '<symbol id="${id}" viewBox="0 ${descent} ${unitsPerEm} ${unitsPerEm}">'
+ '<path d="${d}"></path>'
+ '<path d="${d}"></path>'
+ '</symbol>';


Expand Down
2 changes: 1 addition & 1 deletion src/ttf/ttf2woff.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/ttf/util/contour2svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/ttf/woff2ttf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion test/node-spec/adjustttf.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @file adjustttf
* @author mengke01([email protected])
*/
/* globals Int8Array */

const assert = require('assert');
const fs = require('fs');
const TTFReader = require('./fonteditor-core').TTFReader;
Expand Down
2 changes: 1 addition & 1 deletion test/node-spec/font.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @file font
* @author mengke01([email protected])
*/
/* globals Int8Array, before */

const assert = require('assert');
const fs = require('fs');
const Font = require('./fonteditor-core').Font;
Expand Down
2 changes: 1 addition & 1 deletion test/node-spec/otf2ttf.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion test/node-spec/readotf.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion test/node-spec/readttf.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion test/node-spec/writettf.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
3 changes: 1 addition & 2 deletions test/spec/ttf/font.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
* @file font
* @author mengke01([email protected])
*/
/* eslint-disable fecs-no-require */
/* globals before */

import assert from 'assert';
import {readData} from '../data';
import Font from 'fonteditor-core/ttf/font';
Expand Down
1 change: 0 additions & 1 deletion test/spec/ttf/ttf2woff.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {

Expand Down
29 changes: 14 additions & 15 deletions test/spec/ttf/woff2.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* @file woff2 enc and dec
* @author mengke01([email protected])
*/
/* globals before */

import assert from 'assert';
import {readData} from '../data';
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down

0 comments on commit c238aea

Please sign in to comment.