-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extension backport #49
Changes from all commits
2230f6a
0382fe3
988edff
eea93d2
f5d7e5c
19edfe4
432323b
ead5a75
3f4a5f2
c1a4c2d
7c2ce06
efa41a8
ee00670
06166c3
8b05475
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* Copyright 2016 Google Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const manifestParser = require('../../helpers/manifest-parser'); | ||
|
||
class ManifestBackgroundColor { | ||
|
||
static get tags() { | ||
return ['Manifest']; | ||
} | ||
|
||
static get description() { | ||
return 'Contains background_color'; | ||
} | ||
|
||
static audit(inputs) { | ||
let hasBackgroundColor = false; | ||
const manifest = manifestParser(inputs.manifest).value; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we want to reparse the manifest in every audit? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess we can do it in the gather. |
||
|
||
if (manifest) { | ||
hasBackgroundColor = (!!manifest.background_color); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you're going to actually want As we figure out our reporters, we're likely going to want to capture whether there's no background color because it wasn't included or because the background color was invalid (based on |
||
} | ||
|
||
return { | ||
value: hasBackgroundColor, | ||
tags: ManifestBackgroundColor.tags, | ||
description: ManifestBackgroundColor.description | ||
}; | ||
} | ||
} | ||
|
||
module.exports = ManifestBackgroundColor; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* Copyright 2016 Google Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const manifestParser = require('../../helpers/manifest-parser'); | ||
|
||
class ManifestIcons192 { | ||
|
||
static get tags() { | ||
return ['Manifest']; | ||
} | ||
|
||
static get description() { | ||
return 'Contains 192px icons'; | ||
} | ||
|
||
static audit(inputs) { | ||
let hasIcons = false; | ||
const manifest = manifestParser(inputs.manifest).value; | ||
|
||
if (manifest && manifest.icons) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. kind of ridiculous, but you want something like:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I checked this one, seemed good :) I filter then bounce down to a bool. You get undefined if you can't find the entry in the array. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, my suggestion is only necessary if they include multiple sizes on the same icon, so you have to parse the sizes entry. If they only have one size entry your check is equivalent to this |
||
const icons192 = manifest.icons.raw.find(i => i.sizes === '192x192'); | ||
hasIcons = (!!icons192); | ||
} | ||
|
||
return { | ||
value: hasIcons, | ||
tags: ManifestIcons192.tags, | ||
description: ManifestIcons192.description | ||
}; | ||
} | ||
} | ||
|
||
module.exports = ManifestIcons192; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* Copyright 2016 Google Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const manifestParser = require('../../helpers/manifest-parser'); | ||
|
||
class ManifestIcons { | ||
|
||
static get tags() { | ||
return ['Manifest']; | ||
} | ||
|
||
static get description() { | ||
return 'Contains icons'; | ||
} | ||
|
||
static audit(inputs) { | ||
let hasIcons = false; | ||
const manifest = manifestParser(inputs.manifest).value; | ||
|
||
if (manifest) { | ||
hasIcons = (!!manifest.icons); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
|
||
return { | ||
value: hasIcons, | ||
tags: ManifestIcons.tags, | ||
description: ManifestIcons.description | ||
}; | ||
} | ||
} | ||
|
||
module.exports = ManifestIcons; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,21 +13,35 @@ | |
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
module.exports = function(data) { | ||
// See how compressed the HTML _could_ be if whitespace was removed. | ||
// This could be a lot more aggressive. | ||
let htmlNoWhiteSpaces = data.html | ||
.replace(/\n/igm, '') | ||
.replace(/\t/igm, '') | ||
.replace(/\s+/igm, ' '); | ||
|
||
let htmlLen = Math.max(1, data.html.length); | ||
let htmlNoWhiteSpacesLen = htmlNoWhiteSpaces.length; | ||
let ratio = Math.min(1, (htmlNoWhiteSpacesLen / htmlLen)); | ||
|
||
return { | ||
'minify-html': ratio | ||
}; | ||
}; | ||
const manifestParser = require('../../helpers/manifest-parser'); | ||
|
||
class ManifestName { | ||
|
||
static get tags() { | ||
return ['Manifest']; | ||
} | ||
|
||
static get description() { | ||
return 'Contains name'; | ||
} | ||
|
||
static audit(inputs) { | ||
let hasName = false; | ||
const manifest = manifestParser(inputs.manifest).value; | ||
|
||
if (manifest) { | ||
hasName = (!!manifest.name); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
|
||
return { | ||
value: hasName, | ||
tags: ManifestName.tags, | ||
description: ManifestName.description | ||
}; | ||
} | ||
} | ||
|
||
module.exports = ManifestName; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* Copyright 2016 Google Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const manifestParser = require('../../helpers/manifest-parser'); | ||
|
||
class ManifestShortName { | ||
|
||
static get tags() { | ||
return ['Manifest']; | ||
} | ||
|
||
static get description() { | ||
return 'Contains short_name'; | ||
} | ||
|
||
static audit(inputs) { | ||
let hasShortName = false; | ||
const manifest = manifestParser(inputs.manifest).value; | ||
|
||
if (manifest) { | ||
hasShortName = (!!manifest.short_name); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
|
||
return { | ||
value: hasShortName, | ||
tags: ManifestShortName.tags, | ||
description: ManifestShortName.description | ||
}; | ||
} | ||
} | ||
|
||
module.exports = ManifestShortName; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* Copyright 2016 Google Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const manifestParser = require('../../helpers/manifest-parser'); | ||
|
||
class ManifestStartUrl { | ||
|
||
static get tags() { | ||
return ['Manifest']; | ||
} | ||
|
||
static get description() { | ||
return 'Contains start_url'; | ||
} | ||
|
||
static audit(inputs) { | ||
let hasStartUrl = false; | ||
const manifest = manifestParser(inputs.manifest).value; | ||
|
||
if (manifest) { | ||
hasStartUrl = (!!manifest.start_url); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
|
||
return { | ||
value: hasStartUrl, | ||
tags: ManifestStartUrl.tags, | ||
description: ManifestStartUrl.description | ||
}; | ||
} | ||
} | ||
|
||
module.exports = ManifestStartUrl; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these should be static
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ha, I didn't mean to state that so strongly. More like they can be static since they aren't keeping track of state or anything
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's fine. I changed it.