Skip to content

Commit

Permalink
Added initial boilerplate for caniuse provider
Browse files Browse the repository at this point in the history
  • Loading branch information
amilajack committed Dec 4, 2016
1 parent d3d6603 commit 78c0bcb
Show file tree
Hide file tree
Showing 668 changed files with 208 additions and 609 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2016 Amila Welihinda

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
19 changes: 11 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
"keywords": [
"eslint",
"browser",
"compatibility",
"api"
"api",
"lint",
"caniuse"
],
"author": "",
"license": "MIT",
Expand All @@ -25,11 +26,14 @@
"homepage": "https://github.com/amilajack/eslint-plugin-compat#readme",
"scripts": {
"build": "cross-env NODE_ENV=production babel src --out-dir lib && npm run build-web",
"lint": "cross-env NODE_ENV=test eslint src test",
"lint": "eslint --ignore-path .gitignore --format=node_modules/eslint-formatter-pretty . *.js",
"spec": "jest",
"test": "cross-env NODE_ENV=test npm run lint && npm run spec && npm run build",
"version": "npm run build"
},
"jest": {
"testEnvironment": "node"
},
"devDependencies": {
"babel-cli": "^6.18.0",
"babel-eslint": "^7.1.1",
Expand All @@ -43,21 +47,20 @@
"babel-register": "^6.18.0",
"chai": "^3.5.0",
"cross-env": "^3.1.3",
"eslint": "^3.11.0",
"eslint": "^3.11.1",
"eslint-config-airbnb": "^13.0.0",
"eslint-plugin-flowtype": "^2.28.2",
"eslint-formatter-pretty": "^1.1.0",
"eslint-plugin-flowtype": "^2.29.1",
"eslint-plugin-flowtype-errors": "^1.5.0",
"eslint-plugin-fp": "^2.2.0",
"eslint-plugin-immutable": "^1.0.0",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-jsx-a11y": "^3.0.1",
"eslint-plugin-jsx-a11y": "^2.0.1",
"eslint-plugin-promise": "^3.4.0",
"eslint-plugin-react": "^6.7.1",
"husky": "^0.11.9",
"jest-cli": "^17.0.3",
"json-loader": "^0.5.4",
"mocha": "^3.2.0",
"npm-check": "^5.4.0",
"webpack": "^1.13.3"
},
"dependencies": {
Expand Down
59 changes: 59 additions & 0 deletions src/DetermineCompat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// @flow
import { rules } from './providers/index';


// @HACK: This is just for testing purposes. Its used to mimic the actual
// 'polyfill' property that will eventually be user configurable. Its
// hardcoded for now
const tempPolyfills = new Set(['typed-array']);

export type Targets = string[];

export type ESLintNode = {
type: string,
callee: {
type: string,
computed: bool,
object: {
type: string,
name: string
},
property: {
type: string,
name: string
}
}
}

export type Node = {
ASTNodeType: string,
id: string,
object: string,
property: string,
isValid: (node: Object, eslintNode: ESLintNode) => bool;
}

/**
* Check if the feature is supported
*/
function DetermineCompat(node: ESLintNode, polyfills: Set<string>, targets: string[]): bool {
// Given the AST, find all the matching AST nodes and validate each one

}

/**
* Return false if a if a rule fails
*/
function Validate(node: ESLintNode): bool {
// Find the corresponding rules for a node by it's ASTNodeType
return rules
.filter((rule: Node): bool =>
// Validate ASTNodeType
rule.ASTNodeType !== node.type &&
// Check if polyfill is provided
!tempPolyfills.has(rule.id)
)
.some((rule: Node): bool => rule.isValid(node, node));
}

export default DetermineCompat;
58 changes: 43 additions & 15 deletions src/providers/CanIUseProvider.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,52 @@
// @flow
type node = {
ASTNodeType: string,
object: string,
property: string
}
import { readFileSync } from 'fs';
import type { Node, ESLintNode, Targets } from '../DetermineCompat';


export const supportedTargets: Targets = [
'chrome', 'firefox', 'opera', 'safari', 'android', 'ie', 'edge',
'ios_saf', 'op_mini', 'android', 'bb', 'op_mob', 'and_chr', 'and_ff',
'ie_mob', 'and_uc', 'samsung'
];

function isValid(node: Node, eslintNode: ESLintNode, targets: Targets): bool {
// Filter non-matching objects and properties
if (
!eslintNode.callee.object.name === node.object ||
!eslintNode.callee.property.name === node.property
) return false;

export function Provider(_node: node): bool {
// Check if polyfill is provided
global.doo = _node.object + {};
// Check the CanIUse database to see if targets are supported
const caniuseRecord: Object = JSON.parse(
readFileSync(`./caniuse/features-json/${node.id}.json`).toString()
).stats;

// Check if targets are supported. By default, get the latest version of each
// target environment
return targets.some((target: Object): bool => {
const versions = Object.values(caniuseRecord[target]);
const latest = versions[versions.length - 1];
return latest !== 'n';
});
}

export default {
'typed-array': {
const CanIUseProvider: Node[] = [
// ex. Float32Array()
{
id: 'typed-array',
ASTNodeType: 'CallExpression',
object: 'document',
property: 'ServiceWorker'
property: 'ServiceWorker',
isValid
},
'document-queryselector': {
// ex. document.querySelector()
{
id: 'query-selector',
ASTNodeType: 'CallExpression',
global: 'document',
property: 'querySelector'
object: 'document',
property: 'querySelector',
isValid
}
};
];

export default CanIUseProvider;
Empty file added src/providers/KangaxProvider.js
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 78c0bcb

Please sign in to comment.