1
0
Fork 0

chore(core): Linter fixes

This commit is contained in:
Joost De Cock 2022-09-15 06:29:10 +02:00
parent a76af50900
commit 56427cc4bd
10 changed files with 43 additions and 91 deletions

View file

@ -31,7 +31,7 @@ export function Part() {
return this
}
Part.prototype.macroClosure = function (args) {
Part.prototype.macroClosure = function () {
let self = this
let method = function (key, args) {
let macro = utils.macroName(key)
@ -59,7 +59,7 @@ Part.prototype.getId = function (prefix = '') {
}
/** Returns a value formatted for units provided in settings */
Part.prototype.unitsClosure = function (value) {
Part.prototype.unitsClosure = function () {
const self = this
const method = function (value) {
if (typeof value !== 'number')
@ -267,8 +267,8 @@ Part.prototype.shorthand = function () {
shorthand.paths = new Proxy(this.paths || {}, pathsProxy)
// Proxy the snippets object
const snippetsProxy = {
get: function (target, prop, receiver) {
return Reflect.get(...arguments)
get: function (...args) {
return Reflect.get(...args)
},
set: (snippets, name, value) => {
// Constructor checks
@ -340,12 +340,12 @@ Part.prototype.isEmpty = function () {
if (Object.keys(this.snippets).length > 0) return false
if (Object.keys(this.paths).length > 0) {
for (var p in this.paths) {
for (const p in this.paths) {
if (this.paths[p].render && this.paths[p].length()) return false
}
}
for (var p in this.points) {
for (const p in this.points) {
if (this.points[p].attributes.get('data-text')) return false
if (this.points[p].attributes.get('data-circle')) return false
}

View file

@ -393,7 +393,7 @@ function asPath(bezier, debug = false, log = false) {
}
/** Joins path segments together into one path */
function joinPaths(paths, closed = false, log = false) {
function joinPaths(paths, closed = false) {
let joint = new Path(paths[0].debug).withLog(paths[0].log).move(paths[0].ops[0].to)
let current
for (let p of paths) {

View file

@ -310,7 +310,6 @@ Pattern.prototype.sampleParts = function () {
Pattern.prototype.sampleRun = function (parts, anchors, run, runs, extraClass = false) {
this.draft()
for (let i in this.parts) {
let anchor = false
let dx = 0
let dy = 0
if (this.parts[i].points.anchor) {
@ -474,7 +473,7 @@ Pattern.prototype.__loadPlugins = function () {
return this
}
Pattern.prototype.__loadPlugin = function (plugin, data, explicit = false) {
Pattern.prototype.__loadPlugin = function (plugin, data) {
this.plugins[plugin.name] = plugin
if (plugin.hooks) this.__loadPluginHooks(plugin, data)
if (plugin.macros) this.__loadPluginMacros(plugin)
@ -711,7 +710,7 @@ Pattern.prototype.__resolveParts = function (count = 0) {
// If so, resolve recursively
if (len > count) return this.__resolveParts(len)
for (const [name, part] of Object.entries(this.__parts)) {
for (const part of Object.values(this.__parts)) {
this.config = addPartConfig(part, this.config, this.store)
}

View file

@ -27,12 +27,12 @@ Stack.prototype.addPart = function (part) {
}
/* Returns a list of parts in this stack */
Stack.prototype.getPartList = function (part) {
Stack.prototype.getPartList = function () {
return [...this.parts]
}
/* Returns a list of names of parts in this stack */
Stack.prototype.getPartNames = function (part) {
Stack.prototype.getPartNames = function () {
return [...this.parts].map((p) => p.name)
}

View file

@ -224,7 +224,7 @@ Svg.prototype.renderText = function (point) {
}
Svg.prototype.escapeText = function (text) {
return text.replace(/\"/g, '“')
return text.replace(/"/g, '“')
}
Svg.prototype.renderCircle = function (point) {
@ -234,7 +234,7 @@ Svg.prototype.renderCircle = function (point) {
}
/** Returns SVG code for a snippet */
Svg.prototype.renderSnippet = function (snippet, part) {
Svg.prototype.renderSnippet = function (snippet) {
let x = round(snippet.anchor.x)
let y = round(snippet.anchor.y)
let scale = snippet.attributes.get('data-scale') || 1

View file

@ -27,7 +27,6 @@ describe('Design', () => {
const settings = {}
settings[key] = ['one', 'two']
const Pattern = new Design(settings)
const m = Pattern.config.parts
expect(Pattern.config[key].length).to.equal(2)
expect(Pattern.config[key][0]).to.equal('one')
expect(Pattern.config[key][1]).to.equal('two')

View file

@ -184,7 +184,7 @@ describe('Part', () => {
const part = pattern.__createPartWithContext()
part.hooks.preDraft = [
{
method: function (p) {
method: function () {
count++
},
},
@ -218,7 +218,7 @@ describe('Part', () => {
const design = new Design()
const pattern = new design()
const part = pattern.__createPartWithContext()
const { Path, paths, Point } = part.shorthand()
const { Path, paths } = part.shorthand()
paths.seam = new Path()
expect(part.isEmpty()).to.be.true
})

View file

@ -1035,7 +1035,7 @@ describe('Path', () => {
const b = new Point(10, 10)
const p1 = new Path().move(a).line(b)
expect(invalid).to.equal(false)
const p2 = new Path().withLog(log).noop('test').insop(false, p1)
new Path().withLog(log).noop('test').insop(false, p1)
expect(invalid).to.equal(true)
})
@ -1044,7 +1044,7 @@ describe('Path', () => {
const log = { warning: () => (invalid = true) }
const a = new Point(0, 0)
const b = new Point(10, 10)
const p1 = new Path().move(a).line(b)
new Path().move(a).line(b)
expect(invalid).to.equal(false)
try {
new Path().withLog(log).noop('test').insop('test')
@ -1058,7 +1058,7 @@ describe('Path', () => {
let invalid = false
const log = { warning: () => (invalid = true) }
expect(invalid).to.equal(false)
const p1 = new Path().withLog(log).attr()
new Path().withLog(log).attr()
expect(invalid).to.equal(true)
})
@ -1066,7 +1066,7 @@ describe('Path', () => {
let invalid = false
const log = { warning: () => (invalid = true) }
expect(invalid).to.equal(false)
const p1 = new Path().withLog(log).attr('test')
new Path().withLog(log).attr('test')
expect(invalid).to.equal(true)
})
@ -1142,7 +1142,7 @@ describe('Path', () => {
it('Should log a warning when calling shiftFractionalong but fraction is not a number', () => {
const part = {
name: 'test',
draft: ({ paths, Path, Point, points }) => {
draft: ({ Path, Point, points }) => {
points.a = new Path().move(new Point(0, 0)).line(new Point(0, 40)).shiftFractionAlong()
return part
},
@ -1158,7 +1158,7 @@ describe('Path', () => {
it('Should log a warning when splitting a path on a non-point', () => {
const part = {
name: 'test',
draft: ({ paths, Path, Point, points }) => {
draft: ({ Path, Point, points }) => {
points.a = new Path().move(new Point(0, 0)).line(new Point(0, 40)).split()
return part
},

View file

@ -5,52 +5,6 @@ const expect = chai.expect
describe('Pattern', () => {
describe('Pattern.draft()', () => {
const partA = {
name: 'test.partA',
measurements: ['head', 'knee'],
optionalMeasurements: ['chest', 'waist'],
options: {
optA: { pct: 40, min: 20, max: 80 },
},
draft: () => {},
}
const partB = {
name: 'test.partB',
measurements: ['head', 'knee'],
optionalMeasurements: ['knee'],
after: partA,
plugins: [
{
name: 'testPlugin',
hooks: {
preRender: () => {},
},
},
],
options: {
optB: { deg: 40, min: 20, max: 80 },
},
draft: () => {},
}
const partC = {
name: 'test.partC',
measurements: ['head', 'knee'],
optionalMeasurements: ['knee'],
from: partB,
options: {
optC: { pct: 20, min: 10, max: 30 },
},
draft: () => {},
}
const Pattern = new Design({
data: {
name: 'test',
version: '1.2.3',
},
parts: [partC],
})
const pattern = new Pattern()
it('Pattern.draft() should draft according to settings', () => {
let count = 0

View file

@ -204,7 +204,7 @@ describe('Pattern', () => {
options: { optionB: { pct: 12, min: 2, max: 20 } },
measurements: ['measieB'],
optionalMeasurements: ['optmeasieB', 'measieA'],
draft: ({ points, Point, paths, Path }) => {
draft: ({ points, Point, paths, Path, part }) => {
points.b1 = new Point(2, 2)
points.b2 = new Point(22, 22)
paths.b = new Path().move(points.b1).line(points.b2)
@ -217,7 +217,7 @@ describe('Pattern', () => {
options: { optionC: { deg: 5, min: 0, max: 15 } },
measurements: ['measieC'],
optionalMeasurements: ['optmeasieC', 'measieA'],
draft: ({ points, Point, paths, Path }) => {
draft: ({ points, Point, paths, Path, part }) => {
points.c1 = new Point(3, 3)
points.c2 = new Point(33, 33)
paths.c = new Path().move(points.c1).line(points.c2)
@ -232,7 +232,7 @@ describe('Pattern', () => {
options: { optionR: { dflt: 'red', list: ['red', 'green', 'blue'] } },
measurements: ['measieR'],
optionalMeasurements: ['optmeasieR', 'measieA'],
draft: ({ points, Point, paths, Path }) => {
draft: ({ points, Point, paths, Path, part }) => {
points.r1 = new Point(4, 4)
points.r2 = new Point(44, 44)
paths.r = new Path().move(points.r1).line(points.r2)
@ -355,7 +355,7 @@ describe('Pattern', () => {
options: { optionB: { pct: 12, min: 2, max: 20 } },
measurements: ['measieB'],
optionalMeasurements: ['optmeasieB', 'measieA'],
draft: ({ points, Point, paths, Path }) => {
draft: ({ points, Point, paths, Path, part }) => {
points.b1 = new Point(2, 2)
points.b2 = new Point(22, 22)
paths.b = new Path().move(points.b1).line(points.b2)
@ -368,7 +368,7 @@ describe('Pattern', () => {
options: { optionC: { deg: 5, min: 0, max: 15 } },
measurements: ['measieC'],
optionalMeasurements: ['optmeasieC', 'measieA'],
draft: ({ points, Point, paths, Path }) => {
draft: ({ points, Point, paths, Path, part }) => {
points.c1 = new Point(3, 3)
points.c2 = new Point(33, 33)
paths.c = new Path().move(points.c1).line(points.c2)
@ -381,7 +381,7 @@ describe('Pattern', () => {
options: { optionD: { dflt: 'red', list: ['red', 'green', 'blue'] } },
measurements: ['measieD'],
optionalMeasurements: ['optmeasieD', 'measieA'],
draft: ({ points, Point, paths, Path }) => {
draft: ({ points, Point, paths, Path, part }) => {
points.d1 = new Point(4, 4)
points.d2 = new Point(44, 44)
paths.d = new Path().move(points.d1).line(points.d2)
@ -483,8 +483,8 @@ describe('Pattern', () => {
name: 'example',
version: 1,
hooks: {
preRender: function (svg, attributes) {
svg.attributes.add('freesewing:plugin-example', version)
preRender: function (svg) {
svg.attributes.add('freesewing:plugin-example', 1)
},
},
}
@ -504,8 +504,8 @@ describe('Pattern', () => {
name: 'example1',
version: 1,
hooks: {
preRender: function (svg, attributes) {
svg.attributes.add('freesewing:plugin-example1', version)
preRender: function (svg) {
svg.attributes.add('freesewing:plugin-example1', 1)
},
},
}
@ -513,8 +513,8 @@ describe('Pattern', () => {
name: 'example2',
version: 2,
hooks: {
preRender: function (svg, attributes) {
svg.attributes.add('freesewing:plugin-example2', version)
preRender: function (svg) {
svg.attributes.add('freesewing:plugin-example2', 2)
},
},
}
@ -529,8 +529,8 @@ describe('Pattern', () => {
name: 'example',
version: 1,
hooks: {
preRender: function (svg, attributes) {
svg.attributes.add('freesewing:plugin-example', version)
preRender: function (svg) {
svg.attributes.add('freesewing:plugin-example', 1)
},
},
}
@ -546,8 +546,8 @@ describe('Pattern', () => {
name: 'example',
version: 1,
hooks: {
preRender: function (svg, attributes) {
svg.attributes.add('freesewing:plugin-example', version)
preRender: function (svg) {
svg.attributes.add('freesewing:plugin-example', 1)
},
},
}
@ -562,8 +562,8 @@ describe('Pattern', () => {
name: 'example',
version: 1,
hooks: {
preRender: function (svg, attributes) {
svg.attributes.add('freesewing:plugin-example', version)
preRender: function (svg) {
svg.attributes.add('freesewing:plugin-example', 1)
},
},
}
@ -584,7 +584,7 @@ describe('Pattern', () => {
const Pattern = new Design()
const pattern = new Pattern()
let count = 0
pattern.on('preDraft', function (pattern) {
pattern.on('preDraft', function () {
count++
})
pattern.draft()
@ -600,7 +600,7 @@ describe('Pattern', () => {
name: 'test',
version: '0.1-test',
hooks: {
preDraft: function (pattern) {
preDraft: function () {
count++
},
},
@ -616,10 +616,10 @@ describe('Pattern', () => {
version: '0.1-test',
hooks: {
preDraft: [
function (pattern) {
function () {
count++
},
function (pattern) {
function () {
count++
},
],